Last active
August 1, 2017 19:10
-
-
Save gt50/9723299bb947271390f647db74e7368f 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