题干:
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
总结一下我解这道题的几种思路,并附上耗时和分析
注:由于 leetcode 上不同时期得到的耗时有比较大的差别,我的操作时间是2018.11.11左右。
解法一:
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
array_len = len(nums)
for i in range(0, array_len-1):
for j in range(i&#