Title Description
LL particularly good mood today, because he bought a deck of cards and found that there actually has two king, two small king (the deck was originally 54 ^ _ ^) ... he randomly drawn from the five brand, wanted to Cece own luck, see if you can be able to get straight, if able to get it, he decided to buy a sports lottery, hey! ! "Red A, 3 of spades, Wang, King, square piece 5", "Oh My God!" Straight ..... LL is not happy, he thought, decides \ Amy can be seen as any number, and regarded as A 1, J is 11, Q is 12, K 13. The above five cards can become "1,2,3,4,5" (king size and 2, respectively seen as 4), "So Lucky!". LL decided to buy sports lottery friends. Now, I ask you to use this piece of card simulate the above procedure, and then tell us how LL luck, if the card can be composed of straight to output true, otherwise it will output false. For convenience, you can think of king size is 0.
class Solution: DEF IsContinuous (Self, Numbers): # Write code here Wallpaper IF len (Numbers) <. 5 : return False # counting the number of 0 nOfZero = numbers.count (0) # sort numbers.sort () # sequence interval value is initialized to 0 sumOfGap = 0 # traversing a non-increasing sequence portion 0 for I in Range (nOfZero, len (Numbers) -. 1 ): Small = Numbers [I] Big = Numbers [I +. 1 ] #Comparison with the current value of the next, then there is an equal if the sub- IF Small == Big: return False the else : # if different, the difference therebetween is obtained minus 1, if the continuous value 0, or both of there are gaps between the sumOfGap + = (Big-Small -. 1 ) # determine the number and sequence of nonzero part interval value of 0, if the interval value is not less than 0, it indicates that satisfy the continuity condition IF nOfZero> = sumOfGap: return True the else : return False