mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Added the set solution for str_diff_solution
This commit is contained in:
parent
83ad7ff23a
commit
d96b6179a9
|
@ -31,7 +31,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"# Constraints\n",
|
||||
"\n",
|
||||
"* Can we assume the strings are ASCII?\n",
|
||||
" * Yes\n",
|
||||
|
@ -76,6 +76,15 @@
|
|||
"\n",
|
||||
"Complexity:\n",
|
||||
"* Time: O(m+n), where m and n are the lengths of s, t\n",
|
||||
"* Space: O(1)\n",
|
||||
"\n",
|
||||
"### Set - Difference\n",
|
||||
"\n",
|
||||
"* A set is an unordered collection of unique elements.\n",
|
||||
" * Return a string of a new set with an element in set(t) that is not in set(s).\n",
|
||||
"\n",
|
||||
"Complexity:\n",
|
||||
"* Time: O(m+n), where m and n are the lengths of s, t\n",
|
||||
"* Space: O(1)"
|
||||
]
|
||||
},
|
||||
|
@ -88,7 +97,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 19,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
|
@ -122,7 +131,13 @@
|
|||
" result ^= ord(char)\n",
|
||||
" for char in str2:\n",
|
||||
" result ^= ord(char)\n",
|
||||
" return chr(result)"
|
||||
" return chr(result)\n",
|
||||
"\n",
|
||||
" def find_diff_set(self, str1, str2):\n",
|
||||
" if str1 is None or str2 is None:\n",
|
||||
" raise TypeError('str1 or str2 cannot be None')\n",
|
||||
" else:\n",
|
||||
" return ''.join(set(str2) - set(str1))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -134,7 +149,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 20,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
|
@ -173,7 +188,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 21,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
|
@ -192,10 +207,11 @@
|
|||
}
|
||||
],
|
||||
"metadata": {
|
||||
"anaconda-cloud": {},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python [Root]",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
"name": "Python [Root]"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
|
@ -207,7 +223,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.0"
|
||||
"version": "3.5.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
Loading…
Reference in New Issue
Block a user