Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created January 30, 2022 09:15
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 Desolve/2e0e87626e17ebc1f4729134c817fd7e to your computer and use it in GitHub Desktop.
Save Desolve/2e0e87626e17ebc1f4729134c817fd7e to your computer and use it in GitHub Desktop.
0941 Valid Mountain Array
class Solution {
public boolean validMountainArray(int[] A) {
if (A.length < 3 || A[0] >= A[1]) return false;
int i = 0;
while (i + 1 < A.length && A[i] < A[i + 1]) ++i;
if (i + 1 == A.length || A[i] == A[i + 1]) return false;
while (i + 1 < A.length && A[i] > A[i + 1]) ++i;
if (i + 1 == A.length) return true;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment