FAANG · LeetCode #167
Two Sum II — Sorted Array — three-stage drill
1The ProblemMedium
Two Sum II — Sorted Array
Find two numbers in a sorted array that add up to a target.
Examples
[1,3,4,5,7,11], t=9→ [3,4][1,3,4,5], t=20→ []
2The PatternTIME O(n) · SPACE O(1)
Two Pointers
Converging from both ends, comparing as they meet.
Problems using this pattern
3The SolutionRESULT → [3, 4]
Step through it
Initialize: left at 0, right at 5. target = 9.
Step 1 / 6
Arrow keys to navigate · escape to reset