1. Two Sum(https://oj.leetcode.com/problems/two-sum/)解题思路:解法一: 暴力,O(n2)时间复杂度,TLE解法二:利用hash, 记录下数组中每个值对应的下标,再遍历一遍数组,通过查看target-num[i]的值是否在map中来确定另一个数值。...
分类:
编程语言 时间:
2014-10-24 00:16:44
阅读次数:
226
题目描述: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 t...
分类:
其他好文 时间:
2014-09-30 00:24:31
阅读次数:
208
仅提供个人的一种解题思路,未必是最优,仅供各位参考!
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
*
*
* ClassName SolutionTwoSum
*
*
* Description Given an array of integers, find...
分类:
其他好文 时间:
2014-09-11 17:18:32
阅读次数:
199
今晚再刷一题,题目如下:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices o...
分类:
其他好文 时间:
2014-08-20 01:20:15
阅读次数:
197
题目链接:Pairs完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数。总结其实就是“骑驴找马”的问题:即当前遍历ar[i],那么只要看数组中是否存在ar[i]+K或者ar[i]-K就可以了,还是用HashMap在O(1)...
分类:
其他好文 时间:
2014-08-15 17:17:19
阅读次数:
123
文能深情寻萝莉,武能仗义护人妻[问题描述]Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return ...
分类:
其他好文 时间:
2014-08-13 14:51:56
阅读次数:
228
这个题我最开始的思路是:先一个数定下来,然后在除这个数之外的集合里面找另外两个数,最后计算和。如此反复,对于N个数,需要进行N-2次循环。
我遇到的问题就是怎么找另外两个数,其实我想过参照Two Sum里面的解法,就是用Hashtable存,键值对的结构是>,但是构造这个Hashtable就需要O(N^2),后面真正解的时候有需要O(N^2)。
参考了大牛的解法后,明白了找两个数还是用两个下标...
分类:
其他好文 时间:
2014-08-07 13:19:10
阅读次数:
171
题目还原
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 t...
分类:
其他好文 时间:
2014-08-01 02:25:11
阅读次数:
391