I got right answer in vs but wrong in oj in two-sum case [3,2,4], 6?


  • 0
    I
    class Solution {
    

    public:

    vector<int> twoSum(vector<int>& nums, int target) {
        vector<int> ret;
        for(int i = 0; i < nums.size(); i++ )
        {   
            
            auto k = find(nums.begin(), nums.end(), target - nums[i]);
            if (k != nums.end() && k-nums.begin() != i)
    		{
    			ret.push_back(i + 1);
    			ret.push_back(k-nums.begin()+1);
    			return ret;
    		}
            
        }
    }
    

    };


Log in to reply
 

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