Skip to content

Instantly share code, notes, and snippets.

@gt50
Last active August 1, 2017 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gt50/9723299bb947271390f647db74e7368f to your computer and use it in GitHub Desktop.
Save gt50/9723299bb947271390f647db74e7368f 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