Skip to content

Commit b8ce4a5

Browse files
Update datastructures/linked_lists/linked_list.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 76a61b7 commit b8ce4a5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

datastructures/linked_lists/linked_list.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ def get_kth_to_last_node(self, k: int) -> Optional[Node]:
485485
@return: Kth node from the end
486486
@rtype: Node
487487
"""
488-
if k < 0:
489-
raise ValueError("Invalid K value")
488+
if k < 1:
489+
raise ValueError("K must be >= 1")
490490
if k > len(self):
491491
raise IndexError("K longer than linked list")
492492
fast_pointer, slow_pointer = self.head, self.head
@@ -500,7 +500,6 @@ def get_kth_to_last_node(self, k: int) -> Optional[Node]:
500500
while fast_pointer.next:
501501
fast_pointer = fast_pointer.next
502502
slow_pointer = slow_pointer.next
503-
504503
return slow_pointer
505504

506505
@abstractmethod

0 commit comments

Comments
 (0)