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 0000000000000000000000000000000000000000..78cc2c155765c4ee88409fa3fe64f2807d172929 --- /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 0000000000000000000000000000000000000000..c3d9ef970247b40037e6c10082f37c8a540aa186 --- /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