这道题我用O(n)存O(1)取的时候会超时,但是用O(1)存O(n)取就不会超时,个人觉得是因为测试代码中存比取要多得多。。其实觉得最好的方法应该是O(logn)存取,用两个二分搜索,但是还没太想明白应该用什么数据结构能实现public class TwoSum { private H...
分类:
其他好文 时间:
2015-11-27 07:59:49
阅读次数:
162
1 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...
分类:
其他好文 时间:
2015-11-05 22:15:12
阅读次数:
254
1. TitleTwo Sum2. Http addresshttps://leetcode.com/problems/two-sum/3. The questionGiven an array of integers, find two numbers such that they add up ...
分类:
其他好文 时间:
2015-11-01 19:15:34
阅读次数:
113
问题链接:https://leetcode.com/problems/two-sum/ 解法1:50ms class?Solution?{
public:
????vector<int>?twoSum(vector<int>&?nums,?int?target)?{
????????vector<int>?copy?=?nums;...
分类:
其他好文 时间:
2015-10-28 15:56:34
阅读次数:
161
[LeetCode]1. 2Sum题目:https://leetcode.com/problems/two-sum/,解答:http://www.cnblogs.com/aprilcheny/p/4823576.html;[LeetCode]2. 3Sum题目:https://leetcode.co...
分类:
其他好文 时间:
2015-10-17 20:46:41
阅读次数:
171
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-10-17 17:34:39
阅读次数:
262
用 Hash Table 实现Time : O(n)Space: O(n)import java.util.HashMap;public class Solution { public int[] twoSum(int[] nums, int target) { HashMap ...
分类:
其他好文 时间:
2015-10-13 20:54:52
阅读次数:
225
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-10-13 10:22:26
阅读次数:
156
Design and implement a TwoSum class. It should support the following operations:addandfind.add- Add the number to an internal data structure.find- Fin...
分类:
其他好文 时间:
2015-10-13 10:19:29
阅读次数:
139