classSolution { public: vector<int> twoSum(vector<int>& nums, int target){ vector<int> res; map<int, int> values; map<int, int>::iterator iter; for (int i = 0; i < nums.size(); i++) { iter = values.find(target - nums[i]); if (iter != values.end()) { res.push_back(iter->second); res.push_back(i); return res; } values[nums[i]] = i; } } };
编译时,报如下错误信息:
1 2 3 4 5
solution.cpp: In member function twoSum Line 5: Char 23: error: control reaches end of non-void function [-Werror=return-type] map<int, int> values; ^~~~~~ cc1plus: some warnings being treated as errors