Three Sum
Given an array nums, return every triple of values [a, b, c] taken from three different positions such that a + b + c = 0.
The same triple of values must appear only once, however many positions could make it. Return the triples in any order, with the values of each triple in any order.
Constraints
- 3 ≤ length of
nums≤ 1,000 - -100,000 ≤
nums[i]≤ 100,000
Example 1
Input
nums = [-1,0,1,2,-1,-4]
Output
[[-1,-1,2],[-1,0,1]]
Why:
Two different triples; [-1, 0, 1] can be made from either -1 but counts once.
Example 2
Input
nums = [0,1,1]
Output
[]
Why:
No triple adds up to 0.
Example 3
Input
nums = [0,0,0]
Output
[[0,0,0]]
Why:
The three zeros.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –