class Solution {public: vector> threeSum(vector& nums) { vector> result;
sort(nums.begin(), nums.end());
for(int i = 0; i < nums.size()-3; i++)
{
int a = nums[i];
int start = i +1;
int end = nums.size()-1;
while(start < end)
{
if(a + nums[start] + nums[end] == 0)
{
result.push_back({a, nums[start], nums[end]});
}
else if(a + nums[start] + nums[end] > 0)
end -= 1;
else
start += 1;
}
}
return result;
}
};
Run Code Status: Memory Limit Exceeded