mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Polish linked list palindrome challenge and solution
Update constraints and solution code.
This commit is contained in:
parent
0611967dee
commit
98a71e72e9
|
@ -34,9 +34,15 @@
|
|||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
"* Can we assume this is a non-circular, singly linked list?\n",
|
||||
" * Yes\n",
|
||||
"* Is a single character or number a palindrome?\n",
|
||||
" * No\n",
|
||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||
" * Yes\n",
|
||||
"* Can we use additional data structures?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume this fits in memory?\n",
|
||||
" * Yes"
|
||||
]
|
||||
},
|
||||
|
@ -182,21 +188,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.5.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
|
@ -33,9 +33,15 @@
|
|||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
"* Can we assume this is a non-circular, singly linked list?\n",
|
||||
" * Yes\n",
|
||||
"* Is a single character or number a palindrome?\n",
|
||||
" * No\n",
|
||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||
" * Yes\n",
|
||||
"* Can we use additional data structures?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume this fits in memory?\n",
|
||||
" * Yes"
|
||||
]
|
||||
},
|
||||
|
@ -119,10 +125,10 @@
|
|||
"\n",
|
||||
" # Compare the reversed list with the original list\n",
|
||||
" # Only need to compare the first half\n",
|
||||
" iterations_to_compare_half = length // 2\n",
|
||||
" iterations = length // 2\n",
|
||||
" curr = self.head\n",
|
||||
" curr_reversed = reversed_list.head\n",
|
||||
" for _ in range(0, iterations_to_compare_half):\n",
|
||||
" for _ in range(iterations):\n",
|
||||
" if curr.data != curr_reversed.data:\n",
|
||||
" return False\n",
|
||||
" curr = curr.next\n",
|
||||
|
@ -229,21 +235,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.5.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
Loading…
Reference in New Issue
Block a user