Runtime error last execute input [-3,4,3,90],0 what's wrong with my codes?


  • 0
    Z

    #include <iostream>
    #include <hash_map>
    #include <utility>
    #include <vector>
    using namespace std;
    vector<int> vresult;
    class Solution {
    public:
    vector<int> twoSum(vector<int> &numbers, int target) {
    map<int,pair<int,int> > mp;
    int count=1;
    for(vector<int>::iterator it = numbers.begin();it != numbers.end();++it,++count)
    {
    mp[*it] = make_pair(*it,count);
    }
    map<int,pair<int,int> >::iterator mit;
    for(vector<int>::iterator it = numbers.begin();it != numbers.end();++it)
    {
    mit = mp.find(target-*it);
    if(mit != mp.end()&&(mp[*it].second!=mit->second.second))
    {
    vresult.push_back(mp[*it].second);
    vresult.push_back(mit->second.second);
    return vresult;
    }

        }
    }
    

    };


Log in to reply
 

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