‘hash_map’ was not declared in this scope


  • 0
    H
    class Solution {
    public:
        vector<int> twoSum(vector<int>& nums, int target) {
    		hash_map<int, int> numshash;
    		vector<int> result;
    		for (int i = 0; i < nums.size(); i++)
    		{
    			int x = nums[i];
    			if (numshash.find(target - x) != numshash.end())
    			{
    				result.push_back(numshash.find(target - x)->second + 1);
    				result.push_back(i + 1);
    				return result;
    			}
    			else
    				numshash.insert(make_pair(x, i));
    				
    		}        
        }
    };

  • 1

    use unordered_map instead. hash_map is deprecated and is not part of the C++ standard.


Log in to reply
 

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