成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

leetcode-846-Hand of Straights

xiguadada / 3195人閱讀

摘要:題意分出組連續(xù)的個元素的數(shù)組思路比較簡單,直接循環(huán)刪除連續(xù)的數(shù)組,如此循環(huán)反復(fù)。

題意:分出n組連續(xù)的W個元素的數(shù)組
思路:比較簡單,直接循環(huán)刪除連續(xù)的數(shù)組,如此while循環(huán)反復(fù)。
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)

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/42371.html

相關(guān)文章

  • [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

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<