Skip to content

Commit 1573aa4

Browse files
authored
Create 1. Two Sum.cpp
1 parent 0556b9c commit 1573aa4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

1. Two Sum.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//题目链接:https://leetcode.com/problems/two-sum/
2+
class Solution {
3+
public:
4+
vector<int> twoSum(vector<int>& nums, int target) {
5+
for(size_t i{0}; i < nums.size(); i++){
6+
for(size_t j{0}; j < nums.size(); j++){
7+
if(i != j){
8+
if(nums[i] + nums[j] == target){
9+
return vector<int>{i,j};
10+
}
11+
}
12+
}
13+
}
14+
}
15+
};

0 commit comments

Comments
 (0)