Skip to content

Instantly share code, notes, and snippets.

@gt50
Created August 1, 2017 19:11
Show Gist options
  • Save gt50/9744b8dd07baf8545ed0966fe2bff47c to your computer and use it in GitHub Desktop.
Save gt50/9744b8dd07baf8545ed0966fe2bff47c to your computer and use it in GitHub Desktop.
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