
二叉树
peace in mind
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[Leetcode]Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f原创 2015-03-30 23:22:54 · 424 阅读 · 0 评论 -
[Leetcode] Convert Sorted Array to Binary Search Tree
题目链接在此 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 基于一个有序数组,建立BST。 直观的做法:取数组中点作为根,左侧数组作为左子树,右侧数组作为右子树,不断递归地建树。 class Solution { publ原创 2017-03-14 19:59:29 · 357 阅读 · 0 评论 -
[Leetcode] Validate Binary Search Tree & Recover Binary Search Tree
这是两道题。 98. Validate Binary Search Tree 99. Recover Binary Search Tree 98题:判断一棵树是不是合法的二叉搜索树(BST)。 BST有个可以用脚后跟想出来的特点:中序遍历可以得到一个递增的序列。那我们就中序遍历,看看他是不是严格递增 就可以了。 那么怎样做到不开辟新的空间呢?用一个last原创 2017-03-14 19:35:13 · 426 阅读 · 0 评论 -
[Leetcode] Binary Tree Level Order Traversal & Binary Tree Zigzag Level Order Traversal
这是两道题: 102. Binary Tree Level Order Traversal 103. Binary Tree Zigzag Level Order Traversal 102这道题就是按层次遍历,但是要把每一层的节点分别存储到vector里面去。 两年前就做过这道题,还写了博客。 当时的做法是硬生生地给每个结点加了个域,用来标记高度。很蹩脚。 今天做10原创 2017-03-14 18:29:13 · 410 阅读 · 0 评论 -
[Leetcode]Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20原创 2015-03-30 22:28:41 · 501 阅读 · 0 评论 -
[Leetcode] Flatten Binary Tree to Linked List
题目链接在此 Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look lik转载 2017-03-02 19:37:41 · 289 阅读 · 0 评论 -
[Leetcode] Subsets
题目链接在此 Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order.The solution set must not contain duplicate subs原创 2015-10-23 16:05:24 · 430 阅读 · 0 评论 -
[leetcode] Kth Smallest Element in a BST
题目链接在此 Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements. Follow原创 2015-08-04 15:49:11 · 494 阅读 · 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 de转载 2015-08-03 15:37:59 · 435 阅读 · 0 评论 -
[Leetcode]Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2015-03-30 22:20:30 · 395 阅读 · 0 评论 -
[Leetcode] Sum Root to Leaf Numbers
题目链接在此 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Fin原创 2017-03-14 20:11:00 · 462 阅读 · 0 评论