Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0809d99

Browse files
author
Khanh Do
committed
Use [-1] for last array item
1 parent bdbcff0 commit 0809d99

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

0189_rotate_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def rotate2(nums, k):
4040
k = k % n # In case k > len(nums), prevent redundant rotations
4141

4242
for _ in range(k):
43-
last = nums[n-1] # The extra O(1) space
43+
last = nums[-1] # The extra O(1) space
4444
for i in range(n):
4545
# Since we're rotating elements to the right, we should traverse the
4646
# index from right-to-left to avoid overwriting previously traversed

0 commit comments

Comments
 (0)