Skip to content

Instantly share code, notes, and snippets.

@sclarson
Last active April 10, 2016 02:02
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 sclarson/71faa64f30a86178ab01ec8917a6ace2 to your computer and use it in GitHub Desktop.
Save sclarson/71faa64f30a86178ab01ec8917a6ace2 to your computer and use it in GitHub Desktop.
def flipCounter(stack):
result = 0
prev = '+'
first = True
for ch in stack:
if ch != prev and not first:
result += 1
prev = ch
first = False
if prev == '-':
result += 1
return result
print "Case #1: " + str(flipCounter("-"))
print "Case #2: " + str(flipCounter("-+"))
print "Case #3: " + str(flipCounter("+-"))
print "Case #4: " + str(flipCounter("+++"))
print "Case #5: " + str(flipCounter("--+-"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment