Rumah > Soal Jawab > teks badan
我在本地电脑上运行了,结果正确,但在leetcode上报错,不知道是代码的问题还是操作错误,求指教。谢谢 class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { int a=0,b=1; vector<int>::iterator ite1= nums.begin(); vector<int>::iterator ite2= ite1+1; vector<int> result; bool found=0; for(;(ite1!= nums.end()&&(found==0));ite1++,a++) { if (*ite1>target) { ite1++; } for(ite2= ite1+1,b=a+1;ite2!= nums.end();ite2++,b++) { if (*ite2>target) { ite2++; } if((*ite1+*ite2)==target) { result.clear(); found=1; result.push_back(a); result.push_back(b); break; } } } return result; };