We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 76a61b7 commit b8ce4a5Copy full SHA for b8ce4a5
datastructures/linked_lists/linked_list.py
@@ -485,8 +485,8 @@ def get_kth_to_last_node(self, k: int) -> Optional[Node]:
485
@return: Kth node from the end
486
@rtype: Node
487
"""
488
- if k < 0:
489
- raise ValueError("Invalid K value")
+ if k < 1:
+ raise ValueError("K must be >= 1")
490
if k > len(self):
491
raise IndexError("K longer than linked list")
492
fast_pointer, slow_pointer = self.head, self.head
@@ -500,7 +500,6 @@ def get_kth_to_last_node(self, k: int) -> Optional[Node]:
500
while fast_pointer.next:
501
fast_pointer = fast_pointer.next
502
slow_pointer = slow_pointer.next
503
-
504
return slow_pointer
505
506
@abstractmethod
0 commit comments