###### tags: `LeetCode` 1.Two Sum === A、暴力法: 想法: 主要使用O(n*n)的方式來處理,直接把目標總和扣掉他來找樹木,找到一個數值,沒有放在字典裏面的話先把它塞到字典裏面, 作法: ``` class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ d={} for i in range(len(nums)): num1 = nums[i] num2 = target -nums[i] if num2 in d: return [d[num2],i] d[num1]=i ``` B、 two pointer
×
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