码迷,mamicode.com
首页 >  
搜索关键字:twosum    ( 457个结果
[leetcode]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 t ...
分类:其他好文   时间:2017-04-12 12:25:20    阅读次数:141
[leetcode]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 t ...
分类:其他好文   时间:2017-04-12 12:25:05    阅读次数:161
Two Sum
classSolution{ public: vector<int>twoSum(vector<int>&nums,inttarget){ vector<int>result; vector<int>::iteratorp; vector<int>::iteratornum=nums.begin(); for(inti=0;i<nums.size();i++) { intflag=target-nums[i]; p=find(nums...
分类:其他好文   时间:2017-04-08 01:31:38    阅读次数:126
刷了两道题
leetcode上的Two Sum和Add Two Numbers. twoSum给出的问题是,给定一个整数数组和一个整数,求其中的哪两个元素的和等于给定的那个整数,并返回这两个元素的索引。 我的思路是,进行两层循环,从数组第一个元素开始,分别与它后面的元素相加,这样就能保证遍历完成时,数组中任意两 ...
分类:其他好文   时间:2017-03-27 11:21:39    阅读次数:151
LeetCode 全解
1.Two Sum 使用hash public int[] twoSum(int[] nums, int target) { int[] res = new int[2]; if (nums == null || nums.length < 2) { return res; } HashMap<In ...
分类:其他好文   时间:2017-03-17 10:45:52    阅读次数:197
Leetcode_001_TwoSum_求和为固定数的两个数的索引
题目描述 给定一个整型数组,在数组中找出两个数使这两个数的和为给定数,从小到大输出这两个数在数组中的位置(我们可以假定输出结果只有一个)。例如,输入:N={1,4,8,20}, target=12,输出:index_1=2, index_2=3 方案一 描述 利用C++中的vector和unorde ...
分类:其他好文   时间:2017-03-14 13:12:21    阅读次数:168
A11:两数之和
给一个整数数组,找到两个数使得他们的和等于一个给定的数 target。 你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标。注意这里下标的范围是 1 到 n,不是以 0 开头。 注意事项 你可以假设只有一组答案。 给一个整数数组,找到两个数使得他们的和等于一个给定的数 ...
分类:其他好文   时间:2017-02-26 17:33:42    阅读次数:222
170. Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find ...
分类:其他好文   时间:2017-01-27 12:57:05    阅读次数:253
leetcode:java中的数组操作
Example:Givennums=[2,7,11,15],target=9, Becausenums[0]+nums[1]=2+7=9, return[0,1].一个数组,一个数字,如果这个数字为数组中任意两个元素之和,那么给出这两个元素的位置索引。publicclassSolution{publicint[]twoSum(int[]nums,inttarget){//定义一个空数组,为储存返..
分类:编程语言   时间:2017-01-05 18:48:28    阅读次数:191
Leetcode 给一个数a和一个向量b,找出该向量b中的2个数相加等于a,并输出这两个数在向量中的位置
看C++primer Plus看的无聊,第一次做Leetcode的练习,本来想做二维向量的,结果始终通不过,查了原因,必须用一维的。。。 一维的答案: class Solution { public: vector<int> twoSum(vector<int>& nums, int target) ...
分类:其他好文   时间:2016-12-27 23:30:57    阅读次数:433
457条   上一页 1 ... 15 16 17 18 19 ... 46 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!