这道题有三种解法: 1.暴力求解,用两层for循环,遍历所有可能的情况,时间复杂度是O(n2) 2.现将数组排序,头尾各设置一个指针,左右两边夹逼寻找,但是这道题要返回的是数的索引,所以这种方式不太合适 3.使用hash的方式,将hash的关键字设置为数组元素,关键字对应着数组元素的索引(要注意ha ...
分类:
其他好文 时间:
2016-05-04 14:34:58
阅读次数:
175
一、问题描述 翻译: 给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。你可以假设每一个输入只有一个结果。举例:输入:nums=[2, 7, 11, 15], target = 9输出:[0,1] 二、解答1.每出现一个值x,直接在数组中寻找是否有等于(target-x)的值 时间复杂度 ...
分类:
编程语言 时间:
2016-04-20 13:39:02
阅读次数:
169
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 ex ...
分类:
编程语言 时间:
2016-04-18 15:24:07
阅读次数:
150
题目: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.Example:
Given nums = [2, 7, 1...
分类:
其他好文 时间:
2016-04-16 19:17:00
阅读次数:
152
1.Two Sum naive 4.Median of Two Sorted Arrays 找两个已排序数组的中位数 直接数可以过,但很蠢,O(m+n)时间 1 class Solution { 2 public: 3 double findMedianSortedArrays(vector<int ...
分类:
其他好文 时间:
2016-04-09 20:37:50
阅读次数:
273
我的leetcode击败90%之旅,该篇章主要完成使用Java实现算法,达到进入10%的阵营。这是第一篇Two Sum...
分类:
编程语言 时间:
2016-04-09 12:23:41
阅读次数:
210
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 ex ...
分类:
其他好文 时间:
2016-04-08 00:35:32
阅读次数:
198
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 n ...
分类:
其他好文 时间:
2016-04-07 13:18:14
阅读次数:
108