findFirstRepetition

Run Settings
LanguagePython
Language Version
Run Command
# input: array of integers # output: the number that repeats first # loop through the array # store the numbers in a hash table # verify the hash table for repetitions def findFirstRepetition(array): #to do: validate the array data = dict() for element in array: if element in data: return element else: data[element]=True print("Hello World!") sample1 = [2,5,1,2,3,5,1,2,4] sample2 = [2,1,1,2,3,5,1,2,4] sample3 = [2,3,4,5] result1 = findFirstRepetition(sample1) result2 = findFirstRepetition(sample2) result3 = findFirstRepetition(sample3) assert(result1 == 2) assert(result2 == 1) assert(result3 == None) print("Good bye cruel world")
Editor Settings
Theme
Key bindings
Full width
Lines