-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Bug Report for https://neetcode.io/problems/three-integer-sum
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
class Solution
{
public List<List> threeSum(int[] nums)
{
Arrays.sort(nums);
List<List>ans=new ArrayList<>();
for(int i=0;i<nums.length;i++)
{
if(i>0 && nums[i]==nums[i-1])
continue;
int target=0-nums[i];
int j=i+1,k=nums.length-1;
while(j<k)
{
Listx=new ArrayList<>();
if(nums[j]+nums[k]==target)
{
x.add(nums[i]);
x.add(nums[j]);
x.add(nums[k]);
ans.add(x);
j++;k--;
if(nums[j]==nums[j-1])
j++;
if(nums[k]==nums[k+1])
k--;
}
else if(nums[j]+nums[k]<target)
{
j++;
}
else
{
k--;
}
}
}
return ans;
}
}
submitted this code and it passed
[-4, 2, 2, 2, 2, 2, 2, 2] tried with this custom input and it failed