题目:二叉树的中序遍历。思路:用递归来写中序遍历非常简单。但是题目直接挑衅说,----->"Recursive
solution is trivial"。好吧。谁怕谁小狗。递归代码: 1 List inOrder = new ArrayList(); 2 3 public
...
分类:
其他好文 时间:
2014-06-29 12:55:36
阅读次数:
176
题目
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
方法
根据树的中序遍历和前序遍历,来构造树,使用递归的思想。
Tre...
分类:
其他好文 时间:
2014-06-20 12:14:49
阅读次数:
262
题目
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 a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
Note: Recur...
分类:
其他好文 时间:
2014-06-20 10:22:00
阅读次数:
221
题目
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
题目
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
方法
根据树的中序遍历和后序遍历,来恢复树,使用递归的思想。
Tr...
分类:
其他好文 时间:
2014-06-07 14:50:37
阅读次数:
231
【题目】
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be...
分类:
其他好文 时间:
2014-06-07 14:28:36
阅读次数:
215
题目链接判断一颗二叉树是否是二叉搜索树(二叉排序树),也就是BST如果该二叉树是BST, 那么对其中序遍历,所得序列一定是单调递增的(不考虑有重复数值的情况)附上代码:
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 *...
分类:
其他好文 时间:
2014-06-07 11:28:18
阅读次数:
254
1. 普通的二分查找2. 查找最左边的值3. 查找最右边的值Worst case
performance: O(log n)Best case performance: O(1)Average case performance: O(log
n)Worst case space complexity...
分类:
其他好文 时间:
2014-06-07 11:19:48
阅读次数:
248
.Net3.5的WCF服务在IIS7中发布后,在IE中访问.svc文件出现以下错误:HTTP 错误
404.17 - Not Found请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。 后来发现在II7的WCF服务网站中中*.svc文件已经被.Net
Framework4.0的处理程序as...
分类:
其他好文 时间:
2014-06-07 09:47:55
阅读次数:
202