-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2.4
More file actions
36 lines (31 loc) · 786 Bytes
/
2.4
File metadata and controls
36 lines (31 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#adds two numbers from linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def push(self, new_data):
new_node = Node(new_data)
new_node.next = self.head
self.head = new_node
return new_node
def printList(self):
current = self.head
while current:
print(current.data)
current = current.next
def addTwoLinkedList(a, b):
l = LinkedList()
while a.next:
sum = a.data + b.data
if sum > 10:
l.push(sum % 10)
a.next.data += 1
else:
l.push(sum)
a = a.next
b = b.next
l.push(a.data + b.data)
return l