演算法:1.two sum
03-03
題目來自
https://leetcode.com/problems/two-sum/description/Two SumTwo SumGiven 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].
思路:
時間複雜度 O(n)
空間複雜度 O(n)
推薦閱讀:
※機器學慣用於金融市場預測難在哪?
※調整數組順序使奇數位於偶數前面
※科技特稿 | 凱西·奧尼爾:盲目信仰大數據的時代必須結束
※012 Integer to Roman[M]
TAG:演算法 |