1 Two Sum
来源:互联网 发布:襄阳樊城区网络问政 编辑:程序博客网 时间:2024/06/06 17:52
这题到处都有。。。无语。。。
我看到了就只能在联系一遍。。。
之前代码:
public class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map= new HashMap<>(); int[] result= new int[2]; for(int i=0; i<nums.length; i++){ if(map.containsKey(target-nums[i])){ result[0]=map.get(target-nums[i]); result[1]=i; break; } else map.put(nums[i], i); } return result; }}
今天的代码,3 min 完成,few typo: forget the the word: new, and a semicolon ;
public class Solution { public int[] twoSum(int[] nums, int target) { int len= nums.length; //if(len==0) return false; // the Q said there is one sulution HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); //<[index], index> int[] result= new int[2]; for(int i=0; i<len; i++){ if(map.containsKey(target-nums[i])){ result[0]=map.get(target-nums[i]); result[1]=i; break; // since there is only one solution; } else map.put(nums[i], i); } return result; }}
0 0
- LeetCode 1 - Two Sum
- leetcode 1 Two Sum
- Leetcode【1】:Two Sum
- [leetcode 1] Two Sum
- 【leetcode-1】Two Sum
- [leetcode 1] Two Sum
- [Leetcode] 1 - Two Sum
- LeetCode (1) Two Sum
- LeetCode 1:《Two Sum》
- 1 Two Sum
- Problem 1: Two Sum
- LeetCode | #1 Two Sum
- 1、Two Sum
- leetcode-1 Two Sum
- Two Sum | LeetCode(1)
- 1 Two Sum
- [Leetcode]1Two Sum
- leetcode 1 Two Sum
- CentOS6.5安装与配置Mysql数据库
- Java异常体系结构
- cuda nvidia driver cudnn 安装
- [BZOJ 1093][ZJOI2007]最大半连通子图(Tarjan+拓扑排序+Dp)
- 自己做工具--用原生js封装一个AJAX插件
- 1 Two Sum
- 《用python写网络爬虫》--利用Google爬虫估算网站大小
- Annotation详解
- UITableView 的横向滑动实现
- 170325 PyQt5-Label背景颜色和文本颜色的设置
- 书籍整理
- 实现MyBatis Mapper XML文件增量动态刷新,自动加载,热加载,热部署
- 我是一只忍者神龟.
- 13 Roman to Integer