Problem statement: Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target n ...
分类:
其他好文 时间:
2017-05-20 21:13:19
阅读次数:
218
Problem statement: 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 ...
分类:
其他好文 时间:
2017-05-20 11:10:31
阅读次数:
232
刷题背景 担心找不到工作。 看think in java略枯燥,传智播客的视频太浅显。 于是刷题练习算法和java。 废话少说。 题: java菜鸟一枚,用自己的编译器便于检查语法错误。 所以首先写了一个main函数,用于测试。 1 public static void main(String[] ...
分类:
编程语言 时间:
2017-05-05 17:13:21
阅读次数:
156
public class Solution { public int[] twoSum(int[] numbers, int target) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); int[] results = ...
分类:
其他好文 时间:
2017-05-03 01:02:58
阅读次数:
528
暴力解法O(n2) 略 —————————————————————————————— java中map的get时间为O(1) C++中为O(logn) 哈希解法第一版 O(n) public class Solution {public int[] twoSum(int[] nums, int ta ...
分类:
其他好文 时间:
2017-04-30 17:21:11
阅读次数:
195
我的做法 time : O(N2) public class Solution { public int[] twoSum(int[] nums, int target) { int[] result = new int[2]; int i = 0, j = 0; for (; i < nums.l ...
分类:
其他好文 时间:
2017-04-28 16:12:13
阅读次数:
181
Two Sum 1 首先,暴力解法也就是遍历数组中的每个数字,在数组中寻找target-当前数字,显然时间复杂度比较高,这是一个O(n²)的算法,而在上述代码中我们使用了一个map以O(n)的空间换时间,由于map的put和contains都是O(1)复杂度的操作,算法的时间复杂度为O(n)。 Tw ...
分类:
其他好文 时间:
2017-04-24 00:04:00
阅读次数:
162
题目: 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 hav ...
分类:
其他好文 时间:
2017-04-16 15:08:14
阅读次数:
157
问题描写叙述: 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