leetcode解题方案--001--TwoSum
来源:互联网 发布:amarra windows 编辑:程序博客网 时间:2024/06/07 18:52
题目
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:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
代码块
public static int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < nums.length; i++) { if (map.containsKey(target-nums[i])) { return new int[]{map.get(target-nums[i]),i}; } else { map.put(nums[i], i); } } return null; }
运行时间 8ms
阅读全文
0 0
- leetcode解题方案--001--TwoSum
- [LeetCode]TwoSum解题报告
- LeetCode 001 TwoSum
- LeetCode-001-TwoSum
- [LeetCode]001-TwoSum
- LeetCode 001 TwoSum
- TwoSum解题
- leetcode 001 —— twosum
- [leetcode]-twoSum
- [leetcode]twoSum
- LeetCode-TwoSum
- 【Leetcode】TwoSum
- LeetCode - TwoSum
- leetcode :twoSum
- leetcode TwoSum
- leetcode twosum
- leetcode--twoSum
- LeetCode twoSum
- golang new和make学习笔记
- 247
- wireshark 基本用法及过虑规则参考
- 生成二维码、自定义二维码
- vimの 命令行模式
- leetcode解题方案--001--TwoSum
- hibernate基础学习
- Linux设置环境变量
- Chat UI library for Android
- Hibernate查询语言(HQL)
- 快速掌握 MongoDB 数据库
- 大数据和 AI 驱动创新实例分享
- sed修炼系列(一):花拳绣腿之入门篇
- 整理