Skip to content

Commit 33bcca6

Browse files
committed
change while to for loop
1 parent de357a4 commit 33bcca6

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Python/chapter02/2.2 - Return Kth to Last/miguel_2.2_soln.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ def kth_to_last(ll: LinkedList, k: int) -> Node:
9999
raise IndexError('list index out of range')
100100
# go size - k steps
101101
n = ll.head
102-
i = 1
103-
while n is not None and i <= ll.size - k:
102+
for i in range(1, ll.size - k + 1):
104103
n = n.next
105-
i += 1
106104
return n
107105

108106

0 commit comments

Comments
 (0)