mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-06 01:18:02 +00:00
Fix #13, PEP8-ify notebooks.
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\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",
|
||||
@@ -92,7 +91,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MyLinkedList(LinkedList):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def is_palindrome(self):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass"
|
||||
@@ -127,7 +126,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPalindrome(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_palindrome(self):\n",
|
||||
" print('Test: Empty list')\n",
|
||||
" linked_list = MyLinkedList()\n",
|
||||
@@ -158,13 +157,15 @@
|
||||
" linked_list.append(2)\n",
|
||||
" linked_list.append(1)\n",
|
||||
" assert_equal(linked_list.is_palindrome(), True)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_palindrome')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestPalindrome()\n",
|
||||
" test.test_palindrome()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -103,22 +103,22 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"class MyLinkedList(LinkedList):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def is_palindrome(self):\n",
|
||||
" if self.head is None or self.head.next is None:\n",
|
||||
" return False\n",
|
||||
" curr = self.head\n",
|
||||
" reversed_list = MyLinkedList()\n",
|
||||
" length = 0\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # Reverse the linked list\n",
|
||||
" while curr is not None:\n",
|
||||
" reversed_list.insert_to_front(curr.data)\n",
|
||||
" length += 1\n",
|
||||
" curr = curr.next\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # Compare the reversed list with the original list\n",
|
||||
" # Only need to compare the first half \n",
|
||||
" # Only need to compare the first half\n",
|
||||
" iterations_to_compare_half = length // 2\n",
|
||||
" curr = self.head\n",
|
||||
" curr_reversed = reversed_list.head\n",
|
||||
@@ -158,7 +158,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPalindrome(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_palindrome(self):\n",
|
||||
" print('Test: Empty list')\n",
|
||||
" linked_list = MyLinkedList()\n",
|
||||
@@ -189,13 +189,15 @@
|
||||
" linked_list.append(2)\n",
|
||||
" linked_list.append(1)\n",
|
||||
" assert_equal(linked_list.is_palindrome(), True)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_palindrome')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestPalindrome()\n",
|
||||
" test.test_palindrome()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@ from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestPalindrome(object):
|
||||
|
||||
|
||||
def test_palindrome(self):
|
||||
print('Test: Empty list')
|
||||
linked_list = MyLinkedList()
|
||||
@@ -33,12 +33,14 @@ class TestPalindrome(object):
|
||||
linked_list.append(2)
|
||||
linked_list.append(1)
|
||||
assert_equal(linked_list.is_palindrome(), True)
|
||||
|
||||
|
||||
print('Success: test_palindrome')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestPalindrome()
|
||||
test.test_palindrome()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user