Here is a 3ms C++ answer


  • 0
    L
     vector<int> twoSum(vector<int>& nums, int target) 
    {
    	int p1, p2;
    	vector<int> ans;
    	for (p1 = 0; p1<nums.size(); p1++)
    	{
    	    p2 = p1 + 1;
    	    ans.push_back(p1);
                while (p2<=nums.size()
    	    {
    	       if (target == (nums[p1] + nums[p2]))
    	      {
                    ans.push_back(p2);
                    return ans;
                  }
                   else 
                         p2++;                  
               }
              ans.erase(ans.begin());
            }
            return ans;
        }
    

Log in to reply
 

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