题目内容: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].

题目分析:Array    Hash table

题目要求输入的是和队列的数值相关的值,输出的适合队列的索引相关的值,那么可以将队列存储在Map当中,Map中的Key是队列中的数值,Value是队列中与数值相关的索引。注意Map的定义语句:

Map <Integer, Integer> map = new HashMap <Integer, Integer>();

题目代码:

1. Two Sum★的更多相关文章

  1. LeetCode - Two Sum

    Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summa ...

  2. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  3. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  4. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  5. BZOJ 3944 Sum

    题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不 ...

  6. [LeetCode] Path Sum III 二叉树的路径和之三

    You are given a binary tree in which each node contains an integer value. Find the number of paths t ...

  7. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  8. [LeetCode] Split Array Largest Sum 分割数组的最大值

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  9. [LeetCode] Sum of Left Leaves 左子叶之和

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  10. [LeetCode] Combination Sum IV 组合之和之四

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

随机推荐

  1. "SQLServer复制需要有实际的服务器名称才能连接到服务器,请指定实际的服务器名"转

     "SQLServer复制需要有实际的服务器名称才能连接到服务器,请指定实际的服务器名" 2014-06-12 12:01:10 最近在学习SQL SERVER的高级复制技术的时候 ...

  2. iOS 之 深复制、浅复制

    深复制不仅复制对象本身,对象持有的属性对象也做了复制. 浅复制之复制对象本身,不对里面的属性进行复制.

  3. 位运算,算术、逻辑运算详解-java篇

    /** * 功能: * 位运算符,原码.反码.补码规则: * 1.二进制的最高位是符号位:0表示正数,1表示负数 * 2.正数的原码.反码.补码都一样 * 3.负数的反码=它的原码符号位不变,其他位取 ...

  4. --@angularJS--浅谈class与Ng-Class的应用

    1.angularjs的表达式是可以写在class里面动态改变其值的,写法如下: □.CSS1.html: <!doctype html><html ng-app="MyC ...

  5. php中利用array_filter过滤数组为空值

    [导读] 在我们开发过程中,判断数组为空时你会想到什么方法呢?首先想到的应该是empty函数,不过直接用empty函数判断为空是不对的,因为当这个值是多维数的时候,empty结果是有值的.其实我们可以 ...

  6. GCD教程(二):多核心的性能

    接上一篇,原帖地址:http://www.dreamingwish.com/dream-2012/of-of-of-performance-of-of-of-of-of-of-of-gcd-intro ...

  7. delphi中panel控件应用

    delphi中的panel控件是怎么使用的?研究了很久了,还是搞不懂,只知道把它放到form上面,其他操作一律不懂了,有谁可以请教一下,如何把其他控件放到里面去呢?谢谢 提问者采纳   直接把控件放到 ...

  8. JavaScript的核心

    对象 ECMAScript做为一个高度抽象的面向对象语言,是通过对象来交互的.即使ECMAScript里边也有基本类型,但是,当需要的时候,它们也会被转换成对象. 一个对象就是一个属性集合,并拥有一个 ...

  9. svn git协同管理

    项目开发过程中总有一些奇奇怪怪的需求出现. 我们的项目管理是使用SVN的,用SVN是历史原因,无法整个项目向Git切换.由于我需要管理SVN,做一些代码合并工作.每次合并都会遇到SVN代码需要对比查看 ...

  10. POJ2774(二分+哈希)

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 27234   Accepted: 11 ...