-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Labels
Description
LeetCode 用户名
Anyuze
问题号码、标题和链接
https://leetcode.cn/problems/two-sum/
Bug Category
示例
描述
When I trying to create the vector variable,I didn't use the correct function to create and modify
你使用的语言
C++
你提交或者运行的代码
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> output(2); // 定义大小为2的vector
for(int a = 0; a < nums.size(); a++) {
for(int b = a + 1; b < nums.size(); b++) { // b从a+1开始可以避免b!=a的判断
if(nums[a] + nums[b] == target) {
output[0] = a;
output[1] = b;
return output; // 找到后立即返回
}
}
}
return output; // 如果没有找到,返回默认值(但题目保证有解)
}
};期望行为
I can fully manage the way to master the logic and how to use vector variable
屏幕截图
No response
额外的上下文
No response