Created
January 30, 2022 09:14
-
-
Save Desolve/81650fdb8adc9337e9ebe7f963469467 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: | |
def validMountainArray(self, A: List[int]) -> bool: | |
if len(A) < 3 or A[0] >= A[1]: return False | |
i = 0 | |
while i + 1 < len(A) and A[i] < A[i + 1]: i += 1 | |
if i + 1 == len(A) or A[i] == A[i + 1]: return False | |
while i + 1 < len(A) and A[i] > A[i + 1]: i += 1 | |
if i + 1 == len(A): return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment