原题地址对于已排序数组,二分法递归构造BST代码: 1 TreeNode *buildBST(vector &num, int i, int j) { 2 if (i > j) 3 return NULL; 4 5 int m = (i + j) /2; 6 T...
分类:
其他好文 时间:
2015-01-30 10:26:25
阅读次数:
158
原题地址跟Convert Sorted Array to Binary Search Tree(参见这篇文章)类似,只不过用list就不能随机访问了。代码: 1 TreeNode *buildBST(ListNode *head, int len) { 2 if (len next; 9 ...
分类:
其他好文 时间:
2015-01-30 10:24:52
阅读次数:
192
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord...
分类:
其他好文 时间:
2015-01-30 06:41:04
阅读次数:
162
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'26: Remove Duplicates from Sorted Arrayhttps://oj.leetcode.com/problems/remove-duplicates-...
分类:
编程语言 时间:
2015-01-30 06:35:01
阅读次数:
183
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.Yo...
分类:
编程语言 时间:
2015-01-30 01:18:23
阅读次数:
310
题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ...
分类:
编程语言 时间:
2015-01-30 01:16:29
阅读次数:
200
题目:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted fro...
分类:
编程语言 时间:
2015-01-30 00:00:31
阅读次数:
368
题目:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first
two lists.
我的解法:
(1)算法思想:
先根据两个链表l1,l2头结点值的大小设置要返回链表的头结点h...
分类:
其他好文 时间:
2015-01-29 17:44:28
阅读次数:
116
题目:
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4
5 6 7 0 1 2).
Find the minimum element.
You may assume no duplicate e...
分类:
其他好文 时间:
2015-01-29 17:41:59
阅读次数:
167
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)).
用二分的方法求合并数组的中值。用找第k大的值来求,不断去掉较小的一半,...
分类:
其他好文 时间:
2015-01-29 12:43:29
阅读次数:
175