标签:两数之和 rate css lazy tar target base div not
#时间复杂度O(N*N),空间复杂度O(1) #暴力法 def twoSum_baoli(nums: List[int], target:int) -> List[int]: for i in range(len(nums)-1): base = nums[i] for j in range(i+1, len(nums)): if base + nums[j]==target: return [i,j]
#时间复杂度O(N),空间复杂度O(1) #哈希表 def twoSum(nums: List[int], target:int) -> List[int]: dict={} for index, num in enumerate(nums): another_num = target - num if another_num in dict: return [dict[another_num], index] dict[num] = index
标签:两数之和 rate css lazy tar target base div not
原文地址:https://www.cnblogs.com/vicky2021/p/14725462.html