Skip to content

Commit b2b3a77

Browse files
committed
レビュー後の改良コードを追加
1 parent 067c333 commit b2b3a77

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

1/4.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<int> twoSum(vector<int>& nums, int target) {
4+
map<int, int> numMap;
5+
for(int index = 0; index < nums.size(); index++){
6+
int numToFind = target - nums[index];
7+
if(numMap.find(numToFind) != numMap.end()){
8+
return { index, numMap[numToFind] };
9+
}
10+
numMap[nums[index]] = index;
11+
}
12+
13+
return {};
14+
}
15+
};

0 commit comments

Comments
 (0)