Created
March 14, 2021 12:05
-
-
Save GeorgCantor/04d2c4d8b4befad139d316bff5809dcd to your computer and use it in GitHub Desktop.
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
public boolean validMountainArray(int[] arr) { | |
if (arr.length < 3 || arr[0] > arr[1]) return false; | |
boolean ascend = true; | |
for (int i = 1; i < arr.length; i++) { | |
if (arr[i - 1] == arr[i]) return false; | |
if (ascend) { | |
if (arr[i - 1] > arr[i]) ascend = false; | |
} else { | |
if (arr[i - 1] < arr[i]) return false; | |
} | |
} | |
return !ascend; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment