【题目】
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
【题意】
给定一个已排序的数组(不存在重复元素),将它转换成一棵平衡二叉搜索树。
【思路】
由于平衡二叉树要求左右子树的高度差绝对值相遇等于1,也就是说左右子树尽可能包含相同数目节点。
则使用二分法来解本题即可。...
分类:
其他好文 时间:
2014-06-20 11:03:31
阅读次数:
246
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./** * Def...
分类:
其他好文 时间:
2014-06-11 22:56:31
阅读次数:
257
Given an array where elements are sorted in
ascending order, convert it to a height balanced BST./** * Definition for binary
tree * public class TreeN...
分类:
其他好文 时间:
2014-06-11 21:58:10
阅读次数:
300
原题地址:https://oj.leetcode.com/problems/merge-k-sorted-lists/题意:Mergeksorted
linked lists and return it as one sorted list. Analyze and describe its com...
分类:
编程语言 时间:
2014-06-11 21:57:07
阅读次数:
399
原题地址:https://oj.leetcode.com/problems/search-insert-position/题意:Given
a sorted array and a target value, return the index if the target is found. If
n...
分类:
编程语言 时间:
2014-06-11 11:28:40
阅读次数:
349
Given a singly linked list where elements are
sorted in ascending order, convert it to a height balanced BST.public class
Solution { /** Convert th...
分类:
其他好文 时间:
2014-06-10 00:22:44
阅读次数:
259
题目...For example,Given input array A = [1,1,2],Your function should return length = 2, and A is now [1,2].
解题思路,
移除数组中的重复元素,并返回新数组的长度。
这个题目应该算是简单的题目。使用两个变量就可以。具体的看代码
代码实现......
分类:
其他好文 时间:
2014-06-08 03:54:22
阅读次数:
279
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).You are
given a target value t...
分类:
其他好文 时间:
2014-06-08 02:05:43
阅读次数:
311
Follow up for "Search in Rotated Sorted
Array":What ifduplicatesare allowed?Would this affect the run-time complexity?
How and why?Write a function to...
分类:
其他好文 时间:
2014-06-08 01:19:29
阅读次数:
320
【题目】
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
【题意】
将一个有序链表转换成平衡二叉树
【思路】
思路跟Convert Sorted Array to Binary Search Tree完全一样...
分类:
其他好文 时间:
2014-06-07 16:20:05
阅读次数:
287