Why did I get a "runtime error"? It works on my computer.


  • 0
    Y

    After I submited it , I got that " runtime error {-3,4,3,90},0"

    class Solution {
    public:
    
        vector<int> twoSum(vector<int> &numbers, int target) {
    		int size=numbers.size();
    		unordered_map<int,int> map;
    		for(int i=0;i<size;i++)
    		{
    			map[numbers[i]]=i+1;
    		}
    
    		for(int i=0;i<size;i++)
    		{
    			if(map.find(target-numbers[i])!=map.end() && target-numbers[i]!=numbers[i])
    			{
    				vector<int> re;
    				re.push_back(map[numbers[i]]);
    				re.push_back(map[target-numbers[i]]);
    				return re;
    			}
    		}
        }
    };

  • 0
    W

    if you add a "return {};" to the end of your code, you will find your get a

    Submission Result: Wrong Answer More Details

    Input: [0,4,3,0], 0 Output: [] Expected: [1,4]


Log in to reply
 

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