We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 425ad28 commit 6e99c79Copy full SHA for 6e99c79
remove_kth_node_from_end_linked_list.py
@@ -0,0 +1,22 @@
1
+# Write a function that takes in the head of a Singly Linked List and
2
+# an integer k (assume that the list has at least k nodes).
3
+# The function should remove the kth node from the end of the list.
4
+# Note that every node in the Singly Linked List has a "value" property storing its value as well as a "next" property
5
+# pointing to the next node in the list or None (null) if it is the tail of the list.
6
+
7
8
+def removeKthNodeFromEnd(head, k):
9
+ count = 1
10
+ first = head
11
+ second = head
12
+ while count <= k:
13
+ count += 1
14
+ second = second.next
15
+ if not second:
16
+ head.value = head.next.value
17
+ head.next = head.next.next
18
+ return
19
+ while second.next:
20
+ first = first.next
21
22
+ first.next = first.next.next
0 commit comments