LeetCode 15. 三数之和-java
原题链接
给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。
注意:答案中不可以包含重复的三元组。
代码案例:1、输入:nums = [-1,0,1,2,-1,-4]
输出:[[-1,-1,2],[-1,0,1]]
2、输入:nums = []
输出:[]
题解
class Solution {
//双指针做法或者哈希表 双指针优先 双指针做法一定要有序
public List<List<Integer>> threeSum(int[] nums) {
List<List<Integer>> st = new ArrayList<List<Integer>>();
// List<List<Integer>> st = new ArrayList<List<Integer>>();
Arrays.sort(nums);
int n = nums.length;
for(int i = 0; i < n ; i ++ )