mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-21 18:52:07 +00:00
update
This commit is contained in:
parent
9ddad129d6
commit
dc42ece1aa
3
src/8/11/P11361.cpp
Normal file
3
src/8/11/P11361.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
int main(){
|
||||||
|
|
||||||
|
}
|
20
src/8/11/two-sum.cpp
Normal file
20
src/8/11/two-sum.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include<vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
vector<int> twoSum(vector<int>& nums, int target) {
|
||||||
|
unordered_map<int, int> m;
|
||||||
|
for(int i=0;i<nums.size();i++){
|
||||||
|
if(auto p = m.find(target-nums[i]);p!=m.end()){
|
||||||
|
return {p->second,i};
|
||||||
|
}
|
||||||
|
m.insert({nums[i],i});
|
||||||
|
}
|
||||||
|
return {0,0};
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user