Skip to content

Three Sum ​

Three Sum — LeetCode

Find all unique triplets in the array that sum to zero.

Approach ​

Sort the array. Fix one element, then the problem becomes a two sum. So, foreach element, find the two sum so that sum = 0.

Remarks ​

No need to iterate through the whole list. Iterate till the sortedNums[i] < 0.