题目
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
方法
数组是有序的,要求创建的二叉树尽量平衡,很容易想到对数组进行二分操作,左边的数组元素是左子树,右边的数组元素是右子树。进行递归操作就可以了。
TreeNode...
分类:
其他好文 时间:
2014-06-20 11:06:46
阅读次数:
257
【题目】
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
题目
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
方法
和有序数组的思想基本一样,将链表进行二分。
TreeNode getBST(ListNode head, int len) {
i...
分类:
其他好文 时间:
2014-06-20 09:46:33
阅读次数:
267
在实际的项目中,从音频设备采集到的音频的类型和编码器类型(aac
,amr)通常是不一致的。那么我们首先需要做重采样的过程。利用swr_convert
重新采样。这时候我们可能会遇到另外一个问题。就是在encode_audio的时候遇到more samples than frame size (av...
分类:
其他好文 时间:
2014-06-13 13:55:45
阅读次数:
405
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
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
题目:convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".
解题思路:这个是个纯粹找规律的题,其他没啥特殊的。下面的例子nRows=4;
找规律按照数组小标开始,寻找下标出现的规律,
1. 第一行和最后一行相邻元素下标之差为 2*nRows-2;
2. 除过第一行和最后一行,其余行要多一个元素,该元素出现的下标和行号有关,比如5 = 1 + 6 - 2,可以总结出规律为 j + 2*nRows-2 - 2*i;
关于 i 和 j 看以看下面...
分类:
其他好文 时间:
2014-06-08 09:11:57
阅读次数:
230
在 SQL Server
中Cast和Convert都是将表达式由一种数据类型转换为另一种数据类型。由于SQL
Server提供两种功能,因此应该选择哪种功能或应该在哪种情况下使用该功能就很容易让人困惑了。CONVERT是专对SQL
Server使用的,使日期与时间值,小数之间转换具有更宽的灵活性。...
分类:
数据库 时间:
2014-06-08 06:28:24
阅读次数:
218
【题目】
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
Implement atoi to convert a string to an integer.
Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca...
分类:
其他好文 时间:
2014-06-07 12:21:30
阅读次数:
284