Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created January 30, 2022 09:14
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/81650fdb8adc9337e9ebe7f963469467 to your computer and use it in GitHub Desktop.
Save Desolve/81650fdb8adc9337e9ebe7f963469467 to your computer and use it in GitHub Desktop.
0941 Valid Mountain Array
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