diff --git "a/2224020087/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2224020087/chapter1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..a46398c00c696f5160c2aa417447e99aa34ebe72 --- /dev/null +++ "b/2224020087/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) { + int n = nums.size(); + for (int i = 0; i < n; ++i) { + for (int j = i + 1; j < n; ++j) { + if (nums[i] + nums[j] == target) { + return {i, j}; + } + } + } + return {}; + } +}; \ No newline at end of file diff --git "a/2224020087/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" "b/2224020087/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\345\255\220\346\225\260\347\273\204\347\232\204\345\222\214.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..71613f189faeb792685230a908c4672b853813a3 --- /dev/null +++ "b/2224020087/chapter1/\346\211\200\346\234\211\345\245\207\346\225\260\351\225\277\345\272\246\347\232\204\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