Skip to content

Instantly share code, notes, and snippets.

@QuantumFractal
Created September 22, 2015 17:00
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 QuantumFractal/1fef85250db887c2eb77 to your computer and use it in GitHub Desktop.
Save QuantumFractal/1fef85250db887c2eb77 to your computer and use it in GitHub Desktop.
def main():
cases = int(input())
for case in range(cases):
print(deletions(input()))
def deletions(s):
# Set our first char
last = s[0]
new = last
# Go through the rest of the chars
for c in s[1:]:
# Don't add it if it's a dupe
if last != c:
new += c
last = c
# Check the lengths to determine the deletions needed
return len(s)-len(new)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment