Skip to content

Instantly share code, notes, and snippets.

@ykdojo
Created March 25, 2019 19:02
Show Gist options
  • Save ykdojo/1694fc503df3b91caef33939b1627f0c to your computer and use it in GitHub Desktop.
Save ykdojo/1694fc503df3b91caef33939b1627f0c 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 current = A[0];
let i = 1;
while (current < A[i] && i < A.length) {
current = A[i];
i++;
}
if (i == 1 || i >= A.length) {
return false;
}
while (current > A[i] && i < A.length) {
current = A[i];
i++;
}
if (i < 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