15. 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. Note: The solution set must not contain duplicate triplets. For example, given array S = [-1, 0, 1, 2, -1, -4],A solution set is:[ [-1, 0, 1], [-1, -1, 2]]
给一个数组S包含n个整数,有没有这样的元素a, b, c使得a + b + c = 0? 找出独特的组合使它们的和为零。
注意:结果的组合不能重复。
举例,给一个数组 S = [-1, 0, 1, 2, -1, -4],
答案组合为:
[
[-1, 0, 1],
[-1, -1, 2]
]
你需要完成以下函数:
/**
* Return an array of arrays of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/
int** threeSum(int* nums, int numsSize, int* returnSize) {
}
这道题的网址是:“https://leetcode.com/problems/3sum/#/description“
|