Please help me eliminate the run time error??


  • -2
    I

    class Solution {
    public:
    vector<int> twoSum(vector<int>& nums, int target)
    {
    vector<int>arr;
    int i,j,k;
    int n=nums.size();
    for(i=0;i<n;i++)
    {
    for(j=0;j<n-1;j++)
    {
    if(nums[j]>nums[j+1])
    {
    int temp=nums[j+1];
    nums[j+1]=nums[j];
    nums[j]=temp;
    }
    }

    }
    
    for(i=0;i<n;i++)
    {
    
        for(j=i+1;j<n;j++)
        {
    
            if(target==nums[i]+nums[j])
                {arr[k]=i+1;
                }
            else
            return {0,0};
        }
    
    }
    

    return arr;
    }
    };enter code here


  • 0
    D

    Hi @ishukla, welcome to Discuss! Please format your code properly by clicking on the edit button and highlight all your code, then click on the {} button.


Log in to reply
 

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