各位大佬帮忙看看,我刷的leetcode的第一题,数组的是数目少的时候程序可以运行,数组变多后就失败了,求指点,拜托

weixin_42179892 weixin_42179892 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面是我的程序:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> fan;
bool a=0;
for(int i=0;i<sizeof(nums);i++)
{
for(int j=i+1;j<sizeof(nums);j++)
{
if (nums[i]+nums[j]==target)
{
a=1;
fan.push_back(i);
fan.push_back(j);
break;
}
}
if(a) break;
}
return fan;
}
};
数组少时,结果如下:
Your input
[815,650,920,125,277,221,336,847,168,23,677,61,400,136,874,363,394,199,863,997,794,587,124,321]
542
Output
[5,23]
Diff
Expected
[5,23]

数组多一个数,结果如下:
Your input:
[1,815,650,920,125,277,221,336,847,168,23,677,61,400,136,874,363,394,199,863,997,794,587,124,321]
542
Output:
[]
Expected:
[6,24]

求大佬帮忙,非常感谢
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
weixin_42179892
新手乐园 33,315 成员 41,769 内容