Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest ...
分类:
其他好文 时间:
2014-06-18 17:25:33
阅读次数:
155
题意:给定一个整数序列 问 只允许相邻的两个数交换 至少需要交换多少次思路:归并排序#include __int64 count;int array[500001],temp[500001]; void merge(int array[],int p,int q,int r) ///// p < ....
分类:
其他好文 时间:
2014-06-18 14:41:06
阅读次数:
197
题目
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d =
target? Find all unique quadruplets in the array which gives the sum of target.
Note:
...
分类:
其他好文 时间:
2014-06-18 12:17:57
阅读次数:
179
题目
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 to the...
分类:
其他好文 时间:
2014-06-18 12:05:44
阅读次数:
244
题目
Write a function to find the longest common prefix string amongst an array of strings.
方法
从第一个字符开始,判断是否相同。
public String longestCommonPrefix(String[] strs) {
if (strs ...
分类:
其他好文 时间:
2014-06-18 11:18:30
阅读次数:
205
Given two sorted integer arrays A and B, merge B into A as one sorted array.
Note:
You may assume that A has enough space (size that is greater or equal to
m + n) to
hold additional ele...
分类:
其他好文 时间:
2014-06-17 23:05:13
阅读次数:
246
题目
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would ...
分类:
其他好文 时间:
2014-06-17 22:39:41
阅读次数:
274
题目
Given an array S of n integers, are there elements a, b, c in S such that a + b + c =
0? Find all unique triplets in the array which gives the sum of zero.
Note:
Elements in a tr...
分类:
其他好文 时间:
2014-06-17 22:04:49
阅读次数:
292
题目
Merge k sorted
linked lists and return it as one sorted list. Analyze and describe its complexity.
方法
使用归并排序的思想,两两合并,直到最终变成一个。
public ListNode mergeKLists(ArrayList lists) {...
分类:
其他好文 时间:
2014-06-17 21:34:41
阅读次数:
183
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complet...
分类:
其他好文 时间:
2014-06-17 14:57:30
阅读次数:
269