资讯专栏INFORMATION COLUMN

leetcode-846-Hand of Straights

xiguadada / 3230人阅读

摘要:题意分出组连续的个元素的数组思路比较简单,直接循环删除连续的数组,如此循环反复。

</>复制代码

  1. 题意:分出n组连续的W个元素的数组
    思路:比较简单,直接循环删除连续的数组,如此while循环反复。

</>复制代码

  1. class Solution(object):
  2. def isNStraightHand(self, hand, W):
  3. # c = collections.Counter(hand)
  4. hand.sort()
  5. print(hand)
  6. while hand:
  7. try:
  8. start=hand[0]
  9. for i in range(W):
  10. hand.remove(start+i)
  11. except Exception as e:
  12. return False
  13. return True
  14. if __name__=="__main__":
  15. # hand = [1, 2, 3, 6, 2, 3, 4, 7, 8]
  16. # W = 3
  17. # hand = [1, 2, 3, 4, 5]
  18. # W = 4
  19. hand=[1,2,3,4,5,6]
  20. W=2
  21. st=Solution()
  22. out=st.isNStraightHand(hand,W)
  23. print(out)

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/42371.html

相关文章

  • [LeetCode] 846. Hand of Straights

    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...

    vslam 评论0 收藏0
  • The Power of Ten – Rules for Developing Safety Cri

    摘要:探测器的代码就是写的,真厉害 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...

    Muninn 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<