题解 | #扑克牌顺子#
扑克牌顺子
https://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param numbers int整型一维数组 # @return bool布尔型 #主要思路是对有效的元素排序, 然后最大值不能比最小值大的超过4, 第二个就是有效元素不能重复 class Solution: def IsContinuous(self , numbers: List[int]) -> bool: # write code here stack = [] list2 = [] for x in numbers: if x ==0: stack.append(x) else: list2.append(x) for i in range(len(list2)-1): for j in range(len(list2)-i-1): if list2[j]>list2[j+1]: list2[j],list2[j+1]=list2[j+1],list2[j] print(list2) print(stack) if list2[-1]-list2[0] >4: return False elif len(set(list2))<len(list2): return False else: return True