算法导论读书笔记(15) -
红黑树的具体实现目录红黑树的简单Java实现红黑树的简单Java实现/** * 红黑树 * * 部分代码参考自TreeMap源码 */public class
RedBlackTree { protected TreeNode root = null; pr...
分类:
其他好文 时间:
2014-06-07 05:08:01
阅读次数:
331
Given an array where elements are sorted in
ascending order, convert it to a height balanced BST./** * Definition for binary
tree * struct TreeNode { ...
分类:
其他好文 时间:
2014-05-30 15:10:23
阅读次数:
227
算法导论读书笔记(14) -
二叉查找树的具体实现目录二叉查找树的简单Java实现二叉查找树的简单Java实现/** * 二叉查找树 * 部分代码参考自TreeMap的源码 */public
class BinarySearchTree { protected TreeNode root = ...
分类:
其他好文 时间:
2014-05-29 07:54:22
阅读次数:
214
问题来源于leetcode上的两道题 Path Sum I &&
II,分别写了两个dfs。1 void dfs(TreeNode node , int sum , ArrayList curPath)2 void
dfs(TreeNode node , int sum , boolean ifEx...
分类:
编程语言 时间:
2014-05-28 13:11:14
阅读次数:
361
题目:计算一棵二叉树所有路径组成的数的总和。思考:也是DFS的基础应用。虽然还是套着别人的DFS框架写的,但是学习通常会经历先模拟,再创新的过程。代码:
1 private int sum = 0; 2 public int sumNumbers(TreeNode root) { 3...
分类:
其他好文 时间:
2014-05-28 11:13:01
阅读次数:
225
算法:通过递归并限定上下限元素的值的范围可以计算package
com.bupt.acm.leetcode;public class ValidBinary { private class TreeNode{ int
val; TreeNode left; ...
分类:
数据库 时间:
2014-05-27 17:17:11
阅读次数:
345
二叉树定义:每个结点最多有两个子树的树struct TreeNode { int val;
TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL),
right(NULL) {} };...
分类:
其他好文 时间:
2014-05-26 23:43:52
阅读次数:
351
算法:1.
对root的左子树做处理,让左子树的根节点作为,根节点的右子树,并让右子树作为左子树根节点的右子树的子树2. 递归遍历右子树public void
flatten(TreeNode root) { if(root==null){ return; ...
分类:
其他好文 时间:
2014-05-26 23:39:49
阅读次数:
253
二叉树非递归访问,借助一个栈,来模拟递归调用过程。struct TreeNode { char
val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL),
right(NULL...
分类:
其他好文 时间:
2014-05-26 22:25:25
阅读次数:
353
对于本题,想到一个中序遍历后,判别是否为回文串的方法,却WA多次
class Solution {
public:
vector vectorValue;
void inOrder(TreeNode* root)
{
if(root!=NULL)
{
inOrder(root->left);...
分类:
其他好文 时间:
2014-05-18 06:38:58
阅读次数:
294