摘要:题意分出组连续的个元素的数组思路比较简单,直接循环删除连续的数组,如此循环反复。
</>复制代码
题意:分出n组连续的W个元素的数组
思路:比较简单,直接循环删除连续的数组,如此while循环反复。
</>复制代码
class Solution(object):
def isNStraightHand(self, hand, W):
# c = collections.Counter(hand)
hand.sort()
print(hand)
while hand:
try:
start=hand[0]
for i in range(W):
hand.remove(start+i)
except Exception as e:
return False
return True
if __name__=="__main__":
# hand = [1, 2, 3, 6, 2, 3, 4, 7, 8]
# W = 3
# hand = [1, 2, 3, 4, 5]
# W = 4
hand=[1,2,3,4,5,6]
W=2
st=Solution()
out=st.isNStraightHand(hand,W)
print(out)
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/42371.html
Problem Alice has a hand of cards, given as an array of integers. Now she wants to rearrange the cards into groups so that each group is size W, and consists of W consecutive cards. Return true if and...
摘要:探测器的代码就是写的,真厉害 New Horizon 探测器的代码就是 JPL 写的,真厉害 http://pixelscommander.com/wp-content/uploads/2014/12/P10.pdf Gerard J. Holzmann NASA/JPL Laboratory for Reliable Software Pasadena, CA 91109 Mo...
阅读 2731·2021-10-14 09:47
阅读 5045·2021-09-22 15:52
阅读 3430·2019-08-30 15:53
阅读 1514·2019-08-30 15:44
阅读 753·2019-08-29 16:41
阅读 1751·2019-08-29 16:28
阅读 510·2019-08-29 15:23
阅读 1722·2019-08-26 12:20