When I submit the code, the page display"Runtime Error",why?


  • 0
    F
    class Solution {
    public:
        vector<int> twoSum(vector<int> &numbers, int target) {
        vector<int> resultvec;
    	map<int,int> findmap;
    	 int sizenum = numbers.size();
    	for (int j=0; j<sizenum-1; j++)
    	{
    		map<int,int>::iterator it = findmap.find(numbers[j]);
    		if (it != findmap.end())
    		{
    		    int index = it->second;
    			resultvec.push_back(j+1);
    			resultvec.push_back(index+1);		
    			break;
    		}
    		else
    		{
    			findmap[target-numbers[j]]=j;
    		}
    	}
    	return resultvec;
        }
    };

Log in to reply
 

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