# Leetcode 1. Two Sum ###### tags: `Leetcode(C++)` 題目 : https://leetcode.com/problems/two-sum/ 想法 : 暴力枚舉,O(nlogn)可以寫MAP。 時間複雜度 : O(n^2)。 程式碼 : ``` class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { int find=0,ans1,ans2; vector<int> ans; for(int i=0 ; i<nums.size()&&(!find) ; i++){ for(int j=i+1 ; j<nums.size()&&(!find) ; j++){ if(nums[i] + nums[j] == target){ ans.push_back(i); ans.push_back(j); } } } return ans; } }; ```
×
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