问题描述
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.
- mode:easy
- tag: array(数组)
暴力解决
对于数组中每个数,遍历后面的数,看是否有满足条件的。
- 时间复杂度: O ( N 2 ) O(N^2) O(N2)
- 空间复杂度: O ( N ) O(N) O(N)
Python
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums))