Tag: 二叉树

Leetcode 236. Lowest Common Ancestor of a Binary Tree

No Picture

题目链接 236. Lowest Common Ancestor of a Binary Tree   根据LCA的定义,二叉树中最小公共祖先就是两个节点p和q最近的共同祖先节点,LCA的定义没什么好解释的,主要是这道题的解法。

Read More »

Leetcode 114. Flatten Binary Tree to Linked List

No Picture

Leetcode 114. Flatten Binary Tree to Linked List   题目意思很简单,就是把一棵二叉数转换为链表,虽然题目中没说以什么样的形式转换,但看下样例就很容易看出来,是以先序遍历的次序转换成链表。这里链表节点还是treenode,只不过它的左节点为空而已。

Read More »

Leetcode 230. Kth Smallest Element in a BST

No Picture

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. 求一个二叉搜索树的第k小值。 题目链接:https://leetcode.com/problems/kth-smallest-element-in-a-bst/

Read More »