Problem
Given an array nums
of n integers, are there elements a, b, c in nums
such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Example
1 | Given array nums = [-1, 0, 1, 2, -1, -4], |
Solution1 (Base solution)
Method: Backtracking
Time Complexity:
Space Complexity:
1 | class Solution: |
or
1 | class Solution: |
Solution2
Method:
Time Complexity: O(n^2)
Space Complexity:
1 | class Solution(object): |
or
1 | class Solution: |