Created
March 1, 2012 01:08
-
-
Save jpetazzo/1946386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
A = [1, 8, -3, 0, 1, 3, -2, 4, 5] | |
def complementary_pairs(K, A): | |
buckets = {} | |
for x in A: | |
if x not in buckets: | |
buckets[x] = 0 | |
buckets[x] += 1 | |
N = 0 | |
for i in buckets: | |
N += buckets[i] * buckets.get(K-i, 0) | |
return N | |
print complementary_pairs(6, A) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def isAnagramOfPalindrome(s): | |
buckets = {} | |
for c in s: | |
if c not in buckets: | |
buckets[c] = 0 | |
buckets[c] += 1 | |
how_many_odds = 0 | |
for v in buckets.values(): | |
if v%2: | |
how_many_odds += 1 | |
return how_many_odds<2 | |
if __name__ == '__main__': | |
import sys | |
s = sys.argv[1] | |
print isAnagramOfPalindrome(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment