From d935d0698d08408ebaca29f34dd5ab1a031c55e5 Mon Sep 17 00:00:00 2001 From: un-lock-able Date: Sun, 27 Jul 2025 23:27:40 +0800 Subject: [PATCH] Initial commit --- .gitignore | 1 + .vscode/c_cpp_properties.json | 20 ++++++++++++++++++++ .vscode/launch.json | 29 +++++++++++++++++++++++++++++ .vscode/tasks.json | 28 ++++++++++++++++++++++++++++ 1-1-two-sum.cpp | 28 ++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 1-1-two-sum.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adb36c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.exe \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a031f9a --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "E:\\Applications\\MSYS2\\ucrt64\\bin\\g++.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "windows-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..18b70d7 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "g++.exe - Build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "E:\\Applications\\MSYS2\\ucrt64\\bin\\gdb.exe", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: g++.exe build active file" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..bfb3b57 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++.exe build active file", + "command": "E:\\Applications\\MSYS2\\ucrt64\\bin\\g++.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "E:\\Applications\\MSYS2\\ucrt64\\bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "compiler: E:\\Applications\\MSYS2\\ucrt64\\bin\\g++.exe" + } + ] +} \ No newline at end of file diff --git a/1-1-two-sum.cpp b/1-1-two-sum.cpp new file mode 100644 index 0000000..228d5de --- /dev/null +++ b/1-1-two-sum.cpp @@ -0,0 +1,28 @@ +#include +#include + +int *twoSum(int *nums, int numsSize, int target, int *returnSize) { + int *ans = (int *)malloc(2 * sizeof(int)); + *returnSize = 2; + for (int i = 0; i < numsSize - 1; i++) { + for (int j = i + 1; j < numsSize; j++) { + if (nums[i] + nums[j] == target) { + ans[0] = i; + ans[1] = j; + return ans; + } + } + } + return ans; +} + +int main() { + int nums[] = {3,3}; + int target = 6; + int *ans = NULL; + int ans_size = 0; + ans = twoSum(nums, sizeof(nums) / sizeof(int), target, &ans_size); + printf("size = %d, ans = [%d, %d]\n", ans_size, ans[0], ans[1]); + free(ans); + return 0; +} \ No newline at end of file