Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions chapter_02/p02_return_kth_to_last.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def kth_to_last(ll, k):
count = 0

while leader:
if count >= k:
if count >= k + 1:
follower = follower.next
count += 1
leader = leader.next
Expand All @@ -24,7 +24,7 @@ def helper(head, k):
return None
helper_node = helper(head.next, k)
counter = counter + 1
if counter == k:
if counter == k + 1:
return head
return helper_node

Expand All @@ -33,8 +33,8 @@ def helper(head, k):

test_cases = (
# list, k, expected
((10, 20, 30, 40, 50), 1, 50),
((10, 20, 30, 40, 50), 5, 10),
((10, 20, 30, 40, 50), 0, 50),
((10, 20, 30, 40, 50), 4, 10),
)


Expand Down
Loading