Skip to content

Instantly share code, notes, and snippets.

@HoweChen
Created March 28, 2019 08:32
Show Gist options
  • Save HoweChen/cff70f9f9671651da166da7af9f1fef0 to your computer and use it in GitHub Desktop.
Save HoweChen/cff70f9f9671651da166da7af9f1fef0 to your computer and use it in GitHub Desktop.
[Monotonic Array 连续性列表 ]Check if Python List is monotone increasing or decreasing #Python
def increasing(A:List[int])->bool:
return all(x<=y for x,y in zip(A,A[1::]))
def decreasing(A:List[int])->bool:
return all(x>=y for x,y in zip(A,A[1::]))
#如果要检查是否是连续上升或下降,就用 or 把两个连起来
def isMonotonic(A: List[int]) -> bool:
return self.increasing(A) or self.decreasing(A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment