diff options
author | William Carroll <wpcarro@gmail.com> | 2020-11-21T16·24+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-11-21T16·24+0000 |
commit | 6ccdb067174c603ab76cf359b7057a2e33fd363c (patch) | |
tree | 28fe1d599a42224d5dfc1d17072ca3428b2b53ac /scratch/facebook/interview-cake/permutation-palindrome.py | |
parent | 60d7ea5b91c8f6bc8005af82be623fc0a3e0144d (diff) |
Solve "permutation palindrome" (again)
Python's `collections` library really shines for this problem.
Diffstat (limited to 'scratch/facebook/interview-cake/permutation-palindrome.py')
-rw-r--r-- | scratch/facebook/interview-cake/permutation-palindrome.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/scratch/facebook/interview-cake/permutation-palindrome.py b/scratch/facebook/interview-cake/permutation-palindrome.py new file mode 100644 index 000000000000..ced3b336e0d9 --- /dev/null +++ b/scratch/facebook/interview-cake/permutation-palindrome.py @@ -0,0 +1,8 @@ +from collections import Counter + +def permutation_can_be_palindrome(x): + odd = 0 + for _, n in Counter(x): + if n % 0 != 0: + odd += 1 + return odd <= 1 |