diff --git "a/2209040079 chapter 1/lc chapter1 \344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040079 chapter 1/lc chapter1 \344\270\244\346\225\260\344\271\213\345\222\214.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..23acd262155a09321febe3d0b58dfe01bf81105d --- /dev/null +++ "b/2209040079 chapter 1/lc chapter1 \344\270\244\346\225\260\344\271\213\345\222\214.cpp" @@ -0,0 +1,14 @@ +class Solution { +public: + vector twoSum(vector& nums, int target) { + unordered_map hash; + for (int i = 0; i < nums.size(); ++i) + { + if (hash.find(target - nums[i]) != hash.end()) + return { hash[target - nums[i]],i }; + else + hash[nums[i]] = i; + } + return {}; +} +}; \ No newline at end of file