forked from keon/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkth_to_last.py
More file actions
44 lines (37 loc) · 679 Bytes
/
kth_to_last.py
File metadata and controls
44 lines (37 loc) · 679 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
37
38
39
40
41
42
43
class Node():
def __init__(self, val = None):
self.val = val
self.next = None
def printKthToLast(head):
"""
Time Complexity: O()
Space Complexity: O()
"""
pass
def printLinkedList(head):
string = ""
while head.next:
string += head.val + " -> "
head = head.next
string += head.val
print(string)
# A A B C D C F G
a1 = Node("A")
a2 = Node("A")
b = Node("B")
c1 = Node("C")
d = Node("D")
c2 = Node("C")
f = Node("F")
g = Node("G")
a1.next = a2
a2.next = b
b.next = c1
c1.next = d
d.next = c2
c2.next = f
f.next = g
# removeDups(a1)
# printLinkedList(a1)
# removeDupsWithoutSet(a1)
# printLinkedList(a1)