Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should ret...
分类:
其他好文 时间:
2014-09-09 12:23:58
阅读次数:
176
关于Redis,下面来自百度百科:redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hashs(哈希类型)。这些数据类型都支持push...
分类:
Web程序 时间:
2014-09-09 12:02:58
阅读次数:
294
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.难度70,与Convert Sorted Array to Binary Sear...
分类:
其他好文 时间:
2014-09-08 06:26:16
阅读次数:
263
觉着自己写的比看到的答案精简,分享一下:
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if(head == NULL) return NULL;
ListNode res(-1);
ListNode* pre = &res;
pr...
分类:
其他好文 时间:
2014-09-08 01:03:16
阅读次数:
267
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l...
分类:
其他好文 时间:
2014-09-07 10:58:14
阅读次数:
185
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ...
分类:
其他好文 时间:
2014-09-06 17:16:13
阅读次数:
252
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:不断将相邻的链表两两合并,知道只剩一个链表为止。 1 class Solution { 2 pub...
分类:
其他好文 时间:
2014-09-06 14:51:13
阅读次数:
172
public class Solution { public void merge(int A[], int m, int B[], int n) { int i=m-1, j=n-1, k=m+n-1; while(i>=0 && j>=0) { ...
分类:
其他好文 时间:
2014-09-05 23:41:02
阅读次数:
181
Problem Description:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
分析:很容易想到的一种解法是将链表中所有的元素保存到数组中,然后每次取中间值进行构造,时间复杂度为O(n),空间复杂度为O(n)。具体...
分类:
其他好文 时间:
2014-09-05 18:14:11
阅读次数:
223