mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Polish permutation solution.
This commit is contained in:
parent
186a192c61
commit
75becf1afb
|
@ -140,18 +140,15 @@
|
|||
"from collections import defaultdict\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def unique_counts(string):\n",
|
||||
" dict_chars = defaultdict(int)\n",
|
||||
" for char in string:\n",
|
||||
" dict_chars[char] += 1\n",
|
||||
" return dict_chars\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def permutations_alt(str1, str2):\n",
|
||||
" if len(str1) != len(str2):\n",
|
||||
" return False\n",
|
||||
" unique_counts1 = unique_counts(str1)\n",
|
||||
" unique_counts2 = unique_counts(str2)\n",
|
||||
" unique_counts2 = defaultdict(int)\n",
|
||||
" unique_counts2 = defaultdict(int)\n",
|
||||
" for char in str1:\n",
|
||||
" unique_counts2[char] += 1\n",
|
||||
" for char in str2:\n",
|
||||
" unique_counts2[char] += 1\n",
|
||||
" return unique_counts1 == unique_counts2"
|
||||
]
|
||||
},
|
||||
|
@ -218,7 +215,6 @@
|
|||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Success: test_permutation\n",
|
||||
"Success: test_permutation\n"
|
||||
]
|
||||
}
|
||||
|
@ -230,21 +226,21 @@
|
|||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 2",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python2"
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.10"
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.4.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
Loading…
Reference in New Issue
Block a user