给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。
注意:答案中不可以包含重复的三元组。
0 <= nums.length <= 3000
−105 <= nums[i] <= 105
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/3sum 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
函数接口定义:
public static List<List<Integer>> threeSum(int[] nums)
裁判测试程序样例:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] array = new int[n];
for(int i = 0; i <n; i++)
array[i] = sc.nextInt();
List<List<Integer>> result = threeSum(array);
for(int i = 0; i < result.