Why wrong output? This is giving me wrong output.


  • 0
    P
    public:
        vector<int> twoSum(vector<int>& nums, int target) 
        {
            int low, high;
            low = 0; high = nums.size()-1;
            vector<int> result;
            sort(nums.begin(), nums.end());
            while(low<high)
            {
                if((nums[low]+nums[high])==target)
                {
                    result.push_back(low);
                    result.push_back(high);
                    return result;
                }
                else if((nums[low]+nums[high])<target)
                {
                    low++;
                }
                else 
                    high--;
            }
        }
    };

Log in to reply
 

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