mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-18 07:18:02 +00:00
Fix #13, PEP8-ify notebooks.
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Do you expect the return to be in reverse order too?\n",
|
||||
" * Yes\n",
|
||||
"* What if one of the inputs is None?\n",
|
||||
@@ -169,10 +168,12 @@
|
||||
"\n",
|
||||
" print('Success: test_add_reverse')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestAddReverse()\n",
|
||||
" test.test_add_reverse()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Do you expect the return to be in reverse order too?\n",
|
||||
" * Yes\n",
|
||||
"* What if one of the inputs is None?\n",
|
||||
@@ -133,7 +132,8 @@
|
||||
" new_carry = 1 if value >= 10 else 0\n",
|
||||
" remainder = value % 10\n",
|
||||
" node = Node(remainder)\n",
|
||||
" node.next = self.__add_reverse__(first_node.next if first_node is not None else None, \n",
|
||||
" node.next = self.__add_reverse__(\n",
|
||||
" first_node.next if first_node is not None else None,\n",
|
||||
" second_node.next if first_node is not None else None,\n",
|
||||
" new_carry)\n",
|
||||
" return node\n",
|
||||
@@ -209,10 +209,12 @@
|
||||
"\n",
|
||||
" print('Success: test_add_reverse')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestAddReverse()\n",
|
||||
" test.test_add_reverse()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -38,9 +38,11 @@ class TestAddReverse(object):
|
||||
|
||||
print('Success: test_add_reverse')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestAddReverse()
|
||||
test.test_add_reverse()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* What if the final node is being deleted, for example a single node list? Do we make it a dummy with value None?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||
@@ -149,10 +148,12 @@
|
||||
"\n",
|
||||
" print('Success: test_delete_node')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestDeleteNode()\n",
|
||||
" test.test_delete_node()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* What if the final node is being deleted, for example a single node list? Do we make it a dummy with value None?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||
@@ -162,10 +161,12 @@
|
||||
"\n",
|
||||
" print('Success: test_delete_node')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestDeleteNode()\n",
|
||||
" test.test_delete_node()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -26,9 +26,11 @@ class TestDeleteNode(object):
|
||||
|
||||
print('Success: test_delete_node')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestDeleteNode()
|
||||
test.test_delete_node()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Is this a singly linked list?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume we are always passed a circular linked list?\n",
|
||||
@@ -165,10 +164,12 @@
|
||||
"\n",
|
||||
" print('Success: test_find_loop_start')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestFindLoopStart()\n",
|
||||
" test.test_find_loop_start()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Is this a singly linked list?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume we are always passed a circular linked list?\n",
|
||||
@@ -194,10 +193,12 @@
|
||||
"\n",
|
||||
" print('Success: test_find_loop_start')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestFindLoopStart()\n",
|
||||
" test.test_find_loop_start()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -39,9 +39,11 @@ class TestFindLoopStart(object):
|
||||
|
||||
print('Success: test_find_loop_start')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestFindLoopStart()
|
||||
test.test_find_loop_start()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Can we assume k is a valid integer?\n",
|
||||
" * Yes\n",
|
||||
"* If k = 0, does this return the last element?\n",
|
||||
@@ -154,10 +153,12 @@
|
||||
"\n",
|
||||
" print('Success: test_kth_to_last_elem')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = Test()\n",
|
||||
" test.test_kth_to_last_elem()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Can we assume k is a valid integer?\n",
|
||||
" * Yes\n",
|
||||
"* If k = 0, does this return the last element?\n",
|
||||
@@ -177,10 +176,12 @@
|
||||
"\n",
|
||||
" print('Success: test_kth_to_last_elem')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = Test()\n",
|
||||
" test.test_kth_to_last_elem()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -25,9 +25,11 @@ class Test(object):
|
||||
|
||||
print('Success: test_kth_to_last_elem')
|
||||
|
||||
|
||||
def main():
|
||||
test = Test()
|
||||
test.test_kth_to_last_elem()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -7,6 +7,7 @@ class Node(object):
|
||||
def __str__(self):
|
||||
return self.data
|
||||
|
||||
|
||||
class LinkedList(object):
|
||||
|
||||
def __init__(self, head=None):
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Is this a singly or doubly linked list?\n",
|
||||
" * Singly\n",
|
||||
"* Is this a circular list?\n",
|
||||
@@ -119,6 +118,7 @@
|
||||
" pass\n",
|
||||
" # TODO: Implement me\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class LinkedList(object):\n",
|
||||
"\n",
|
||||
" def __init__(self, head=None):\n",
|
||||
@@ -284,6 +284,7 @@
|
||||
"\n",
|
||||
" print('Success: test_len\\n')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestLinkedList()\n",
|
||||
" test.test_insert_to_front()\n",
|
||||
@@ -292,6 +293,7 @@
|
||||
" test.test_delete()\n",
|
||||
" test.test_len()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Is this a singly or doubly linked list?\n",
|
||||
" * Singly\n",
|
||||
"* Is this a circular list?\n",
|
||||
@@ -196,6 +195,7 @@
|
||||
" def __str__(self):\n",
|
||||
" return self.data\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class LinkedList(object):\n",
|
||||
"\n",
|
||||
" def __init__(self, head=None):\n",
|
||||
@@ -416,6 +416,7 @@
|
||||
"\n",
|
||||
" print('Success: test_len\\n')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestLinkedList()\n",
|
||||
" test.test_insert_to_front()\n",
|
||||
@@ -424,6 +425,7 @@
|
||||
" test.test_delete()\n",
|
||||
" test.test_len()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -103,6 +103,7 @@ class TestLinkedList(object):
|
||||
|
||||
print('Success: test_len\n')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestLinkedList()
|
||||
test.test_insert_to_front()
|
||||
@@ -111,5 +112,6 @@ def main():
|
||||
test.test_delete()
|
||||
test.test_len()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -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",
|
||||
@@ -161,10 +160,12 @@
|
||||
"\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()"
|
||||
]
|
||||
|
||||
@@ -192,10 +192,12 @@
|
||||
"\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()"
|
||||
]
|
||||
|
||||
@@ -36,9 +36,11 @@ class TestPalindrome(object):
|
||||
|
||||
print('Success: test_palindrome')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestPalindrome()
|
||||
test.test_palindrome()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Can we create additional data structures?\n",
|
||||
" * Yes\n",
|
||||
"* Do you expect the function to return a new list?\n",
|
||||
@@ -168,10 +167,12 @@
|
||||
"\n",
|
||||
" print('Success: test_partition')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestPartition()\n",
|
||||
" test.test_partition()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Can we create additional data structures?\n",
|
||||
" * Yes\n",
|
||||
"* Do you expect the function to return a new list?\n",
|
||||
@@ -193,10 +192,12 @@
|
||||
"\n",
|
||||
" print('Success: test_partition')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestPartition()\n",
|
||||
" test.test_partition()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -37,9 +37,11 @@ class TestPartition(object):
|
||||
|
||||
print('Success: test_partition')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestPartition()
|
||||
test.test_partition()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Is this a singly or doubly linked list?\n",
|
||||
" * Singly\n",
|
||||
"* Can you insert None values in the list?\n",
|
||||
@@ -154,11 +153,13 @@
|
||||
"\n",
|
||||
" print('Success: test_remove_dupes\\n')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestRemoveDupes()\n",
|
||||
" linked_list = MyLinkedList(None)\n",
|
||||
" test.test_remove_dupes(linked_list)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Is this a singly or doubly linked list?\n",
|
||||
" * Singly\n",
|
||||
"* Can you insert None values in the list?\n",
|
||||
@@ -204,11 +203,13 @@
|
||||
"\n",
|
||||
" print('Success: test_remove_dupes\\n')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestRemoveDupes()\n",
|
||||
" linked_list = MyLinkedList(None)\n",
|
||||
" test.test_remove_dupes(linked_list)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -27,10 +27,12 @@ class TestRemoveDupes(object):
|
||||
|
||||
print('Success: test_remove_dupes\n')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestRemoveDupes()
|
||||
linked_list = MyLinkedList(None)
|
||||
test.test_remove_dupes(linked_list)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user