LeetCode算法题1解题思路
原题
1. Two Sum
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:
1 | Given nums = [2, 7, 11, 15], target = 9, |
解题思路
- 首先说下这道题虽然简单,但是我犯错了,准确的说是犯懒了,没有深入思考,一开始做了一个很烂的解答。
- 其次就稍微提示一下,这个需要把数组转成map,时间复杂度能下降一个等级。
代码实现
Golang实现
https://github.com/cook-coder/my-leetcode-solution/tree/master/easy/1