cpp solution without hashmap


  • 0
    X

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


Log in to reply
 

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