1 import java.util.*; 2 3 public class Solution { 4 public int[] twoSum(int[] nums, int target) { 5 Map map = new HashMap(); 6 i...
分类:
其他好文 时间:
2015-08-12 21:32:25
阅读次数:
80
思路:只需遍历一次数组,利用HashMap保存数组元素和下标,如果数组元素存在HashMap的key中,则返回结果,如果不存在,则put到HashMap中,注意,这种遍历保证了数组的下标肯定不小于HashMap中的下标。Java代码: public int[] twoSum(int[] num...
分类:
其他好文 时间:
2015-08-08 14:51:39
阅读次数:
115
class Solution {
public:
vector twoSum(vector& nums, int target)
{
vector twoSum1(2);
map mValueIdex;
map::iterator it;
bool flag=0;
for(int i=0;i<nums.size();i++)
{
//两个一样.
if(num...
分类:
其他好文 时间:
2015-08-06 20:30:36
阅读次数:
108
Two Sum
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 th...
分类:
其他好文 时间:
2015-08-04 23:00:26
阅读次数:
104
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 in...
分类:
其他好文 时间:
2015-08-02 18:20:21
阅读次数:
112
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 nu...
分类:
其他好文 时间:
2015-07-29 11:40:57
阅读次数:
126
看书虽然有必要,但是光看书大家斗志到是没用的,但是没办法,科研项目和互联网没关,只能找点题目来刷了!
不多说,开始!
LeetCode_1 TwoSum
题目说明:
Given an array of integers, find two numbers such that they add up to a specific target number.
The fu...
分类:
其他好文 时间:
2015-07-25 23:06:34
阅读次数:
292
n-sum problemQuestion 2Two SumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum shoul...
分类:
其他好文 时间:
2015-07-21 23:43:37
阅读次数:
210
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 nu...
分类:
其他好文 时间:
2015-07-20 10:37:39
阅读次数:
110
TwoSumGivenanarrayofintegers,findtwonumberssuchthattheyadduptoaspecifictargetnumber.ThefunctiontwoSumshouldreturnindicesofthetwonumberssuchthattheyadduptothetarget,whereindex1mustbelessthanindex2.Pleasenotethatyourreturnedanswers(bothindex1andindex2)arenotz..
分类:
其他好文 时间:
2015-07-16 14:26:57
阅读次数:
100