[英]getting this error expected a declaration. using vscode
getting this error expected a declaration.得到这个错误需要一个声明。 using vscode to solve leetcode problems
使用vscode解决leetcode问题
#include <iostream>
#include <vector>
using std::vector;
class solution{
public:;
<int> twoSum(vector <int>& nums, int target)
{
unordered_map<int, int> _map;
for(int i =0; i < nums.size(); i++){
int num = nums[i];
int complement = target - num;
auto it = _map.find(complement);
if(it != _map.end()){
return {it->second, i};
}
_map[num] = i;
}return {}
}
};
error:错误:
"message": "expected a declaration",
"source": "C/C++",
"startLineNumber": 8,
"startColumn": 4,
"endLineNumber": 8,
"endColumn": 5
You probably want this:你可能想要这个:
...
#include <vector>
#include <unordered_map>
...
using namespace std;
class solution {
public:
vector<int> twoSum(vector <int>& nums, int target)
{
unordered_map<int, int> _map;
for (int i = 0; i < nums.size(); i++) {
int num = nums[i];
int complement = target - num;
auto it = _map.find(complement);
if (it != _map.end()) {
return { it->second, i };
}
_map[num] = i;
}
return {};
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.