Last active
October 12, 2015 20:47
-
-
Save ticky/4085093 to your computer and use it in GitHub Desktop.
Detect if a set of numbers is complete and consecutive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
# coding: utf-8 | |
items = [ | |
[1, 2, 3, 5, 6, 7, 7, 8, 9, 10,11,12], # false | |
[2, 3, 4, 5, 6, 7, 8, 9, 10,11,12], # false | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], # true | |
[1, 2, 2, 4, 5, 6, 7] , # false | |
[1, 2, 3, 4, 5, 7] , # false | |
[3, 5, 1, 2, 4] # true | |
] | |
def isComplete(numberSet): | |
numberSet.sort() | |
length = len(numberSet) | |
expected = range(1, numberSet[-1]+1) | |
if(length != numberSet[-1]): | |
return False | |
return (expected == numberSet) | |
for nums in items: | |
print(isComplete(nums)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment