From bd1864d3af7dce8f709cfcbb198349cf13f75cc5 Mon Sep 17 00:00:00 2001 From: 178****1445 <2823979649@qq.com> Date: Fri, 15 Sep 2023 10:20:05 +0000 Subject: [PATCH] 2209040003 --- ...70\244\346\225\260\344\271\213\345\222\214.cpp" | 14 ++++++++++++++ ...45\207\346\225\260\344\271\213\345\222\214.cpp" | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 "2209040003/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" create mode 100644 "2209040003/chap1/\345\245\207\346\225\260\344\271\213\345\222\214.cpp" diff --git "a/2209040003/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" "b/2209040003/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" new file mode 100644 index 00000000..78cc2c15 --- /dev/null +++ "b/2209040003/chap1/\344\270\244\346\225\260\344\271\213\345\222\214.cpp" @@ -0,0 +1,14 @@ +int* twoSum(int* nums, int numsSize, int target, int* returnSize) { + for (int i = 0; i < numsSize; ++i) { + for (int j = i + 1; j < numsSize; ++j) { + if (nums[i] + nums[j] == target) { + int* ret = malloc(sizeof(int) * 2); + ret[0] = i, ret[1] = j; + *returnSize = 2; + return ret; + } + } + } + *returnSize = 0; + return NULL; +} \ No newline at end of file diff --git "a/2209040003/chap1/\345\245\207\346\225\260\344\271\213\345\222\214.cpp" "b/2209040003/chap1/\345\245\207\346\225\260\344\271\213\345\222\214.cpp" new file mode 100644 index 00000000..c3d9ef97 --- /dev/null +++ "b/2209040003/chap1/\345\245\207\346\225\260\344\271\213\345\222\214.cpp" @@ -0,0 +1,12 @@ +int sumOddLengthSubarrays(int* arr, int arrSize) { + int sum = 0; + for (int start = 0; start < arrSize; start++) { + for (int length = 1; start + length <= arrSize; 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 -- Gitee