摘要:題意分出組連續的個元素的數組思路比較簡單,直接循環刪除連續的數組,如此循環反復。
題意:分出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)
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/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...
閱讀 2632·2021-10-14 09:47
閱讀 4909·2021-09-22 15:52
閱讀 3355·2019-08-30 15:53
閱讀 1428·2019-08-30 15:44
閱讀 669·2019-08-29 16:41
閱讀 1646·2019-08-29 16:28
閱讀 439·2019-08-29 15:23
閱讀 1618·2019-08-26 12:20