Array
15. 3Sum
Brute force is three nested loops — O(n³). Sort first and the picture changes: with the first element nums[i] fixed, you're just looking for two numbers summing to −nums[i] in a sorted array, and…
Loading…
Brute force is three nested loops — O(n³). Sort first and the picture changes: with the first element nums[i] fixed, you're just looking for two numbers summing to −nums[i] in a sorted array, and…
Loading…