Skip to content

Instantly share code, notes, and snippets.

@ykdojo
Created March 25, 2019 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykdojo/52846b3d43bbca564f8472672bc84141 to your computer and use it in GitHub Desktop.
Save ykdojo/52846b3d43bbca564f8472672bc84141 to your computer and use it in GitHub Desktop.
/**
* @param {number[]} A
* @return {boolean}
*/
var validMountainArray = function(A) {
if (A.length < 3) {
return false;
}
let i = 0;
let j = 1;
while (A[i] < A[j] && i < A.length) {
i++;
j++;
}
// i should be at the peak
if (i == 0 || j >= A.length) {
return false;
}
while (A[i] > A[j] && j < A.length) {
i++;
j++;
}
if (j < A.length) {
return false;
} else {
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment