![]() |
#2
rjsp2017-01-14 18:13
|

# include <iostream>
# include <cstdio>
# include <vector>
# include <unordered_map>
using namespace std;
class Sum2
{
public:
vector<int> Sum_2(vector<int> &num, int target)
{
unordered_map<int, int> mapping;
vector<int> Sum2_array;
for (int i = 0; i < num.size(); i++)
mapping[num[i]] = i;
for (int i = 0; i < num.size(); i++)
{
const int gap = target - num[i];
if (mapping.find(gap) != mapping.end() && mapping[gap] > i)
{
Sum2_array.push_back(i + 1);
Sum2_array.push_back(mapping[gap] + 1);
break;
}
}
return Sum2_array;
}
};
int main()
{
Sum2 class_s2;
return 0;
}
代码应该是对的,但是运行起来报错:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/unordered_map:35,
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/c++0x_warning.h:31:2:
error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
我的<unordered_map>是不是没有安装好?还是我的编译器gcc或者g++有问题?
谢谢!