1、Two Sum
2016-01-07 14:24
260 查看
> 1、Two Sum |
Output: index1=1, index2=2
> 2、思路: |
> 3、代码: |
public class Solution(){ public int[] twoSum(int[] nums, int target) { int[] result = new int[2]; Map<Integer,Integer> map = new HashMap<Integer,Integer>(); for(int i = 0 ; i < nums.length ; i++){ if(map.containsKey(target - nums[i])){ result[0] = map.get(target - nums[i]); result[1] = i + 1; return result; } map.put(nums[i],i + 1); } return result; } }
相关文章推荐
- 菜单 PHP 开发中的外围资源性能分析(一)
- 输入一行字符串,把字符串翻转[单词顺序不变]
- web 前端资料
- 5.UITableView基本使用
- 蓝牙代理报错:invalid handle error
- MFC列表控件更改一行的字体颜色
- SHELL变量的几个小题目
- iis的错误页设置不显示详细信息
- VIM入门
- HttpUploader6-queue版本更新说明
- MQTT——java简单测试(二)
- 网易前端JavaScript编码规范【转】
- [AnyDAC][Phys][ODBC][Microsoft][ODBC 驱动管理器]在指定的DSN中,驱动程序和应用程序体系结构不
- 5.1.2. Using Lists as Queues(像队列一样)
- Centos7下openresty自启动配置
- lambda内容的介绍
- bug系列-------sn序列号在烧img之后被损坏
- 判断计算机是大端还是小端
- 指针数组与数组指针的区别
- 配置Eclipse支持java和xml文件的代码补全功能