Skip to content

Instantly share code, notes, and snippets.

@bgnori
Created September 6, 2013 06:21
Show Gist options
  • Save bgnori/6460186 to your computer and use it in GitHub Desktop.
Save bgnori/6460186 to your computer and use it in GitHub Desktop.
coursesera stack sequence solver
source = list(range(10))
stack = []
expected = [6, 5, 4, 3, 2, 1, 0, 7, 8, 9]
while expected:
while not stack or stack[0] != expected[0]:
stack.insert(0, source.pop(0))
print("push", stack[0])
print("pop", stack[0])
stack.pop(0)
expected.pop(0)
print("done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment