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.
Given nums = [2, 7, 11, 15], target = 9,
Because nums + nums = 2 + 7 = 9,
return [0, 1].
Intuitive ideas, violent solutions, two cycles. low efficiency.
The enumerate() function is used to combine a traversable data object (such as a list, tuple, or string) into an index sequence, listing both data and data subscripts, typically used in a for loop.
以下是 enumerate() 方法的语法:
- Sequence – A sequence, iterator, or other support iterative object.
- Start – the starting position of the subscript.
Returns the enumerate object.