Created
August 1, 2017 19:11
-
-
Save gt50/9744b8dd07baf8545ed0966fe2bff47c to your computer and use it in GitHub Desktop.
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
import timeit | |
def array123(arr): | |
return ''.join(list(map(str,arr))).find('123') >= 0 | |
def array123_noob(arr): | |
stack = [0,0,0] | |
for num in arr: | |
stack.append(num) | |
stack.pop(0) | |
if (stack == [1,2,3]): | |
return True | |
return False | |
print(timeit.timeit('array123([1, 1, 2, 3, 1])', globals=globals())) | |
print(timeit.timeit('array123_noob([1, 1, 2, 3, 1])', globals=globals())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment