题目再现
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 O(log (m+n)).
题意解析...
分类:
其他好文 时间:
2014-08-02 18:24:13
阅读次数:
335
问题:有序合并两个有序链表分析:归并排序的合并部分class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { ListNode *helper=new ListNode(0); ...
分类:
其他好文 时间:
2014-08-02 18:17:03
阅读次数:
170
问题:将有序链表中的重复元素删除分析:由于有序,所以p结点是否重复只需要和它的前一节点比较是否相等就可以了,我们可以定义一个helper新头结点链表 将p结点与新链表的尾结点比较,若不相等则加入新链表中。class Solution{public: ListNode *deleteDup...
分类:
其他好文 时间:
2014-08-02 17:47:33
阅读次数:
210
要搜索的对象是一个rotated sorted array,所以从直觉上时间复杂度应该不会超过O(logn)。起初我想尝试修改binary search来解决这个问题,但仔细思考后发现在不断search的过程中,search的boundary是比较难确定的。解决这个题目的另一个思路就是先把pivot...
分类:
其他好文 时间:
2014-08-02 15:21:23
阅读次数:
359
问题描述:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->...
分类:
其他好文 时间:
2014-08-02 01:33:12
阅读次数:
249
问题:将B按顺序合并到A上分析:插入排序,注意A数组为空class Solution{public: void merge(int A[], int m, int B[], int n) { int i,j; if(m==0) { ...
分类:
其他好文 时间:
2014-08-01 22:54:32
阅读次数:
184
题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.题解:之前做过一道是从sorted array转换到BinarySearc....
分类:
编程语言 时间:
2014-08-01 04:54:21
阅读次数:
310
Problem Description:
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you ...
分类:
其他好文 时间:
2014-08-01 00:08:50
阅读次数:
274
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.算法:根据有序数组,生...
分类:
其他好文 时间:
2014-07-31 23:20:00
阅读次数:
270
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-07-31 12:14:56
阅读次数:
222