Skip to content

Commit 1fdd7c6

Browse files
Fix loop condition to prevent duplicate index usage
Updated the while loop condition from `<=` to `<` to ensure that the two-pointer indices do not overlap. This prevents potential errors when processing the array and aligns with the expected logic of the algorithm.
1 parent 0c63099 commit 1fdd7c6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Two Pointers/two_sum_II.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def two_sum_II(nums: List[int], target: int) -> List[int]:
1515

1616
result = []
1717

18-
while left <= right:
18+
while left < right:
1919
current_sum = nums[left] + nums[right]
2020

2121
if current_sum < target:

0 commit comments

Comments
 (0)