LeetCode 20190916

01 two numbers and
this question mainly to find out not understanding the problem as long as two and meet the target to return
if there is no direct return empty return vector

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int length=nums.size();
        vector<int>result;
        for(int i=0;i<length;i++){
            for(int j=i+1;j<length;j++){
                if( nums[i]+nums[j]==target)
                    result.push_back(i);
                    result.push_back(j);
                    return result;
            }
        
        }  
     return result;
    }  
};

02

Published 44 original articles · won praise 9 · views 3359

Guess you like

Origin blog.csdn.net/puying1/article/details/100900340