Skip to content

Commit 2a9fc3c

Browse files
pep8 fix
1 parent 562ae07 commit 2a9fc3c

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

Python/chapter02/2.1 - Remove Dups/Nick.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/python3
2+
'''
3+
Remove Dups! Write code to remove duplicates from an unsorted linked list. FOLLOW UP How would you solve this problem if a temporary buffer is not allowed?
4+
'''
25
import unittest
36

47

Python/chapter02/2.7 - Intersection/Nick.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python3
2-
2+
'''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'''
33
import unittest
44

55

@@ -27,7 +27,8 @@ def appendNode(self, data, next=None):
2727
def printMemoryValues(self):
2828
temp = self.head
2929
while temp:
30-
print('Memory address values: ', hex(id(temp)), ' Values: ', temp.data)
30+
print('Memory address values: ', hex(
31+
id(temp)), ' Values: ', temp.data)
3132
temp = temp.next
3233

3334
def findNode(self, value):
@@ -46,29 +47,28 @@ def findLongest(self, l1, l2):
4647
if not self.head:
4748
print('No list to iterate')
4849
return None
49-
50+
5051
l1count, l2count = 0, 0
5152
temp1, temp2 = l1.head, l2.head
5253
while temp1:
5354
l1count += 1
5455
temp1 = temp1.next
55-
56+
5657
while temp2:
5758
l2count += 1
5859
temp2 = temp2.next
59-
60+
6061
if l1count > l2count:
6162
longest, shortest = l1, l2
6263
else:
6364
longest, shortest = l2, l1
6465
return abs(l1count - l2count), longest, shortest
6566

66-
6767
def intersection(self, l1, l2):
6868
if not l1.head or not l2.head:
6969
print('No list to iterate -> intersection')
7070
return None
71-
71+
7272
diff, longest, shortest = self.findLongest(l1, l2)
7373
temp = longest.head
7474
for x in range(diff):
@@ -80,10 +80,10 @@ def intersection(self, l1, l2):
8080
return temp
8181
temp = temp.next
8282
temp2 = temp2.next
83-
83+
8484
return None
85-
86-
85+
86+
8787
class Test(unittest.TestCase):
8888
@classmethod
8989
def setUpClass(cls):
@@ -103,29 +103,31 @@ def setUpClass(cls):
103103
cls.k.appendNode(6, node)
104104
cls.k.printMemoryValues()
105105

106-
107106
cls.p = SinglyLinkedList()
108107
cls.p.appendNode(1)
109108
cls.p.appendNode(2)
110109
cls.p.appendNode(5)
111110
cls.p.appendNode(1000)
112111
cls.p.appendNode(-22)
113112
cls.p.printMemoryValues()
113+
114114
@classmethod
115115
def tearDownClass(cls):
116116
pass
117117

118-
119118
def printStatement(self, interNode):
120119
if interNode:
121-
print('Nodes intersect at address', hex(id(interNode)), ' Value: ',interNode.data)
120+
print('Nodes intersect at address', hex(
121+
id(interNode)), ' Value: ', interNode.data)
122122
else:
123123
print('Nodes do not intersect')
124+
124125
def test1(self):
125126
interNode = self.l.intersection(self.l, self.k)
126127
interNode2 = self.l.intersection(self.l, self.p)
127128
self.printStatement(interNode)
128129
self.printStatement(interNode2)
129130

131+
130132
if __name__ == '__main__':
131133
unittest.main()

0 commit comments

Comments
 (0)