Skip to content

Instantly share code, notes, and snippets.

@jdiez17
Created October 11, 2015 17:58
Show Gist options
  • Save jdiez17/1e09a60c93df6bc799a4 to your computer and use it in GitHub Desktop.
Save jdiez17/1e09a60c93df6bc799a4 to your computer and use it in GitHub Desktop.
import sys
chars = sorted(sys.stdin.read())[1:]
histogram = {}
for c in chars:
if c in histogram:
histogram[c] += 1
else:
histogram[c] = 1
flag = True
odd, even = 0, 0
for char, count in histogram.items():
if count % 2 != 0:
odd += 1
else:
even +=1
if len(chars) % 2 == 0:
# check there is an even number of every character
flag = odd == 0
else:
if odd == 1:
flag = True
else:
flag = False
print("YES" if flag else "NO")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment