diff --git "a/2209040078/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040078/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..747e054f205c6c7a4500fbdd682220ca851ce490 --- /dev/null +++ "b/2209040078/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 diff --git "a/2209040078/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" "b/2209040078/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..e3a789ead7920b3fd317769544283b934c41f382 --- /dev/null +++ "b/2209040078/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" @@ -0,0 +1,16 @@ +class Solution { +public: + int sumOddLengthSubarrays(vector& arr) { + int sum = 0; + int n = arr.size(); + for (int start = 0; start < n; start++) { + for (int length = 1; start + length <= n; length += 2) { + int end = start + length - 1; + for (int i = start; i <= end; i++) { + sum += arr[i]; + } + } + } + return sum; + } +}; \ No newline at end of file