Skip to content

Commit 0862d95

Browse files
committed
formatting
1 parent 62a7aa0 commit 0862d95

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

chapter-2-linked-lists/2.5-sum-lists.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88
Input: (6 -> 1 -> 7) + (2 -> 9 -> 5). That is, 617 + 295.
99
Output: 9 -> 1 -> 2. That is, 912.
1010
"""
11+
from LL_implementation import LLNode, LinkedList
12+
13+
# Can you assume both numbers have the same number of digits?
14+
15+
def sum_lists(ll1,ll2):
16+
node1 = ll1.head
17+
node2 = ll2.head
18+
list_sum = 0
19+
digit = 0.1
20+
while node1:
21+
digit *= 10
22+
list_sum += (node1.data + node2.data) * digit
23+
node1 = node1.next
24+
node2 = node2.next
25+
while list_sum > 0:
26+
remainder = list_sum % digit
27+
28+
1129

1230

1331

chapter-2-linked-lists/2.6-palindrome.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" 2.6 Palindrome: Implement a function to check if a linked list is a palindrome. """
22

3+
from LL_implementation import LLNode, LinkedList
34

45

56

chapter-2-linked-lists/2.7-intersection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" 2.7 Intersection: Given two (singly) linked lists, determine if the two lists intersect. Return the intersecting node. Note that the intersection is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, then they are intersecting. """
22

3+
from LL_implementation import LLNode, LinkedList
34

45

56

chapter-2-linked-lists/2.8-loop-detection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
"""
1010

11+
from LL_implementation import LLNode, LinkedList
1112

1213

1314

chapter-2-linked-lists/LL_implementation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def add(self, node_data):
4343

4444
def remove(self, node_data):
4545
current = self.head
46+
previous = None
4647
while current.data != node_data:
4748
previous = current
4849
current = current.next

0 commit comments

Comments
 (0)