判断列表是否有序
本帖最后由 Handsome_zhou 于 2022-5-31 14:38 编辑python 判断列表是否有序(升序或者降序)
#判断列表前几个数是否有序
class Solution:
def isAscSorted(self, nums):
n = 4
i = 0
while(i < n - 1):
if nums < nums:
i += 1
else:
return False
return True
def isDescSorted(self, nums):
n = len(nums)
for i in range(n - 1):
if nums >= nums:
continue
else:
return False
return True
if __name__ == '__main__':
nums =
solution = Solution()#实例化类
res = solution.isAscSorted(nums=nums) or solution.isDescSorted(nums)
if not res:
print("无序")
页:
[1]