资讯专栏INFORMATION COLUMN

leetcode-846-Hand of Straights

xiguadada / 3071人阅读

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

题意:分出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

相关文章

  • [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元查看
<