摘要:題意分出組連續(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
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...
閱讀 2670·2021-10-14 09:47
閱讀 4974·2021-09-22 15:52
閱讀 3380·2019-08-30 15:53
閱讀 1477·2019-08-30 15:44
閱讀 711·2019-08-29 16:41
閱讀 1683·2019-08-29 16:28
閱讀 467·2019-08-29 15:23
閱讀 1649·2019-08-26 12:20