Created
January 30, 2022 09:15
-
-
Save Desolve/2e0e87626e17ebc1f4729134c817fd7e to your computer and use it in GitHub Desktop.
0941 Valid Mountain Array
This file contains 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
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