
二叉树
Coding_Reading
待我编码有成 娶你为妻可好
展开
-
leetcode 96. Unique Binary Search Trees
题目: 思路: 以k为根节点的树,左子树为【1,…,K - 1】,右子树为【K + 1,…,N】,定义f(n)为【1,…,n】能产生不同的二叉搜索树的个数,则以K为根节点能产生f(k - 1) * f(n - k)种不同的树。显然f(0) = f(1) = 1。 f(2) = f(0) * f(1) + f(1) * f(0) f(3) = f(0) * f(2) + f(1) * f(1)原创 2017-06-04 23:04:36 · 287 阅读 · 0 评论 -
leetcode100. Same Tree
easy程度题Q:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 判断两个二叉树是否原创 2017-05-20 16:34:24 · 369 阅读 · 0 评论 -
leetcode101. Symmetric Tree
Q:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:1 / \ 2 2 / \ / \ 3 4 4 3But the原创 2017-05-20 16:17:18 · 382 阅读 · 0 评论 -
Morris二叉树遍历算法
Morris二叉树遍历算法 时间复杂度O(N),空间复杂度O(1) 这种方法借鉴了线索化二叉树的思想,但是不占用空间中序遍历方法如下:如果当前节点的左孩子为空,则输出当前节点并将其右孩子作为当前节点。如果当前节点的左孩子不为空,在当前节点的左子树中找到当前节点在中序遍历下的前驱节点。a) 如果前驱节点的右孩子为空,将它的右孩子设置为当前节点。当前节点更新为当前节点的左孩子。b) 如果前驱节点转载 2017-05-19 23:36:16 · 374 阅读 · 0 评论