递归
文章平均质量分 77
ljffdream
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Invert Binary Tree
[题目]Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by原创 2015-06-18 16:30:12 · 715 阅读 · 0 评论 -
【Leetcode】Find the kth in the BST
[题目][思路]BST的特点就是排序性,左边的节点一定比root小,右边的节点一定比root大。另外就是二分性。找第k个,可以先看左边树节点的个数,小于k的话,就保证了肯定是在右边。那么去找右边的k-left.k - left,就变成了新的k.数root所在的树的节点数。这个就是用递归实现。想法就是,如果root自己本身就是null,那么就return 0; 否则至转载 2015-07-08 21:28:09 · 493 阅读 · 0 评论 -
【Leetcode】Lowest Common Ancestor of a Binary Search Tree
【题目】Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defi转载 2015-07-20 21:05:28 · 319 阅读 · 0 评论