-
-
Save antonybudianto/987d98fa413e3ac2907838cabbdee221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function solution(A) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
let len = A.length | |
let arr = new Array(len) | |
for(let i=0; i<len;i++) { | |
let idx = A[i] - 1 | |
if (idx < len) { | |
arr[idx] = arr[idx] || 0 | |
arr[idx]++ | |
} | |
} | |
let curMax = 0; | |
for(let j=0;j<len;j++) { | |
if (curMax < arr[j]) { | |
curMax = arr[j] | |
} | |
if(arr[j] === undefined) return j+1 | |
} | |
return curMax+1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment