# [leetcode 001. Two Sum](https://leetcode.com/problems/two-sum) <font color=#00AF9B>Easy</font> 50.2% - 限制 <ul> <li><code> 2 <= nums.length <= 10^4</code></li> <li><code>-10^9 <= nums[i] <= 10^9</code></li> <li><code>-10^9 <= target <= 10^9 </code></li> </ul> - Sulotion - 時間複雜度: $O(n^2)$ - 空間複雜度: $O(n)$ - 程式碼 ```c++!= class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int>temp; for (int i = 0; i < nums.size()-1; i++) { for (int j = i+1; j < nums.size(); j++) { if (nums[i] + nums[j]==target) { temp.push_back(i); temp.push_back(j); return temp; } } } return temp; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up