error:control reaches end of non-void function [-Werror=return-type]


在做LeetCode上的题目时,出现了这个错误,

原代码如下:

 1 class Solution {
 2 public:
 3     vector<int> twoSum(vector<int>& nums, int target) {
 4         vector<int> v;
 5         unordered_map<int, int> m; 
 6         for(int i=0;i<nums.size();++i)
 7         {
 8             int tt=target-nums[i];
 9             if(m.find(tt)!=m.end())
10             {
11                  v.push_back(m[tt]);
12                 v.push_back(i);
13                 return v;
14             }  
15             else
16                     m[nums[i]]=i;
17         }
18         //return v;
19     }
20 };

可以看到18行被我注释掉了,就是这行缺失导致出现程序可能不会返回值。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM