3Sum
3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Example
For example, given array S = {-1 0 1 2 -1 -4}, A solution set is:
Solution
Solution 1: Add addational for each for the third number and continue use two sum hastable way
Solution 2: Add addational for each for the third number and use sort array and two pointers way to implement.
the key point is that dont forget how to detect the duplicate target ,left right.
考虑到重复值。
Last updated
Was this helpful?