diff --git "a/exercise/LC0001_\345\274\240\344\270\226\344\273\273.cpp" "b/exercise/LC0001_\345\274\240\344\270\226\344\273\273.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..753c6dc4f1445f3a339838890b7e1aba93a1e1e4 --- /dev/null +++ "b/exercise/LC0001_\345\274\240\344\270\226\344\273\273.cpp" @@ -0,0 +1,20 @@ +#include +using namespace std; +// 【题目】力扣001. 两数之和 +// 【难度】简单 +// 【提交】https://leetcode.cn/problems/two-sum/submissions/663172129 +// 【标签】数组;哈希表 +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