Skip to content

Commit 0c63099

Browse files
Add clarification on sorted array assumption in comments
The added comments explain why the two-pointer approach works due to the sorted nature of the input array. This provides context for the algorithm and highlights its dependency on the input's precondition.
1 parent 0a72460 commit 0c63099

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Two Pointers/two_sum_II.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import unittest
44
from typing import List
55

6+
# This approach works because we are told that `nums` is sorted
7+
# If the array was not sorted, we would have to sort it first, and
8+
# incur a O(n log n) time complexity.
69

710
def two_sum_II(nums: List[int], target: int) -> List[int]:
811
n = len(nums)

0 commit comments

Comments
 (0)