LeetCode 1: Two Sum
2015-11-21 09:46
337 查看
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input:numbers={2, 7, 11, 15}, target=9
Output:index1=1, index2=2
LeetCode对于性能要求比较高,因此对于此类查找问题,用hashmap是减少时间复杂度的一个方法。
代码:
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input:numbers={2, 7, 11, 15}, target=9
Output:index1=1, index2=2
LeetCode对于性能要求比较高,因此对于此类查找问题,用hashmap是减少时间复杂度的一个方法。
代码:
相关文章推荐
- curl 与服务器定时
- POJ-1273-最大流裸题。
- [黑马IOS自学第五篇]C语言二维数组,排序法学习
- WINDOWS计划任务设置MYSQL自动备份
- markdown语法
- git分支管理与冲突解决(转载)
- nginx.conf绑定虚拟目录执行PHP
- CI框架学习
- UICollectionView 头视图、 尾视图以及Cell自定制
- 【转载】socket阻塞与非阻塞,同步与异步、I/O模型
- underscore源码解析(实用的功能)
- MYSQL 子查询
- 在java中高效复制一个文件夹里面所有的内容
- layout_gravity和gravity的区别
- 古代建筑的风水知识对未来装饰行业的影响 by oralusa.com
- 正则表达式学习
- 第一章 可伸展的语言
- 利用属性获取文件目录
- UI第九天:UITableView表视图
- Pyscripter为什么总报错?UnicodeEncodeError: 'ascii' codec can't encode characters in position