Created
March 28, 2019 08:32
-
-
Save HoweChen/cff70f9f9671651da166da7af9f1fef0 to your computer and use it in GitHub Desktop.
[Monotonic Array 连续性列表 ]Check if Python List is monotone increasing or decreasing #Python
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
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