Why Runtime error?


  • 0
    E

    class Solution {
    public:
    vector<vector<int>> threeSum(vector<int>& nums) {
    vector<vector<int>> num;
    if(nums.size()<3)
    return num;
    sort(nums.begin(),nums.end());
    for(int i=0;i<nums.size()-2;i++)
    {
    if(num[i]==num[i-1])
    continue;
    int j=i+1;
    int k=nums.size()-1;
    while(j<k)
    {
    if((nums[j]+nums[k])==-nums[i])
    {
    vector<int> result;
    result.push_back(nums[i]);
    result.push_back(nums[j]);
    result.push_back(nums[k]);
    num.push_back(result);
    while(j<k&&nums[j]==nums[j+1])
    {
    j++;
    }
    while(k>j&&nums[k]==nums[k-1])
    {
    k--;
    }
    j++;
    k--;
    }
    else if((nums[j]+nums[k])<-nums[i])
    {
    j++;
    }
    else if((nums[j]+nums[k])>-nums[i])
    {
    k--;
    }
    }
    }
    return num;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.