[LeetCode] 958. Check Completeness of a Binary Tree

2019-01-14
阅读 1 分钟
2.1k
Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2^h nodes inclusive at the last level h.

[LeetCode] 545. Boundary of Binary Tree

2019-01-14
阅读 3 分钟
1.9k
Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and right boundary in order without duplicate nodes.

[LeetCode] 617. Merge Two Binary Trees

2018-12-31
阅读 2 分钟
2.1k
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.

[LeetCode] 894. All Possible Full Binary Trees

2018-12-06
阅读 2 分钟
3.4k
A full binary tree is a binary tree where each node has exactly 0 or 2 children.

[LeetCode] 222. Count Complete Tree Nodes

2018-12-03
阅读 1 分钟
1.9k
Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

[LeetCode] 662. Maximum Width of Binary Tree

2018-11-26
阅读 2 分钟
2.6k
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a full binary tree, but some nodes are null.

[LeetCode] 116. Populating Next Right Pointers in Each Node

2018-11-26
阅读 2 分钟
2.1k
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

[LeetCode] 270. Closest Binary Search Tree Value

2018-11-25
阅读 1 分钟
2k
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.

[LeetCode] 404. Sum of Left Leaves

2018-11-24
阅读 2 分钟
1.6k
There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.

[LeetCode] 663. Equal Tree Partition

2018-11-24
阅读 2 分钟
2.6k
Given a binary tree with n nodes, your task is to check if it's possible to partition the tree to two trees which have the equal sum of values after removing exactly one edge on the original tree.

[LeetCode] 199. Binary Tree Right Side View

2018-11-24
阅读 2 分钟
1.6k
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

[LeetCode] 671. Second Minimum Node In a Binary Tree

2018-11-24
阅读 2 分钟
2.1k
Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes.

[LeetCode] 230. Kth Smallest Element in a BST

2018-11-18
阅读 2 分钟
1.7k
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.

[LeetCode] 652. Find Duplicate Subtrees

2018-11-09
阅读 1 分钟
2.2k
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.

[LeetCode] 669. Trim a Binary Search Tree

2018-11-08
阅读 2 分钟
2.3k
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree.

[LeetCode] 814. Binary Tree Pruning

2018-10-29
阅读 2 分钟
1.3k
We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1.

[LeetCode] 428. Serialize and Deserialize N-ary Tree

2018-10-25
阅读 3 分钟
5.3k
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

[LeetCode] 124. Binary Tree Maximum Path Sum

2018-10-25
阅读 1 分钟
1.8k
For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.

[LeetCode] 226. Invert Binary Tree

2018-10-22
阅读 2 分钟
1.7k
Trivia:This problem was inspired by this original tweet by Max Howell:

[LeetCode] 314. Binary Tree Vertical Order Traversal

2018-10-09
阅读 2 分钟
3.1k
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).

[LeetCode] 429. N-ary Tree Level Order Traversal (vs. LC102)

2018-10-02
阅读 2 分钟
2.6k
Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

[LeetCode] 590. N-ary Tree Postorder Traversal (vs. LC145)

2018-10-02
阅读 3 分钟
2.4k
Given an n-ary tree, return the postorder traversal of its nodes' values.For example, given a 3-ary tree:Return its postorder traversal as: [5,6,3,2,4,1].Note: Recursive solution is trivial, could you do it iteratively?

[LeetCode] 589. N-ary Tree Preorder Traversal (vs. LC144)

2018-10-02
阅读 3 分钟
2.8k
Given an n-ary tree, return the preorder traversal of its nodes' values.For example, given a 3-ary tree:Return its preorder traversal as: [1,3,5,6,2,4].Note: Recursive solution is trivial, could you do it iteratively?

[LeetCode] 559. Maximum Depth of N-ary Tree

2018-10-02
阅读 1 分钟
3k
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

[LeetCode] 543. Diameter of Binary Tree

2018-09-26
阅读 1 分钟
1.6k
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

[LeetCode] 297. Serialize and Deserialize Binary Tree

2018-09-20
阅读 2 分钟
1.3k
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

[LeetCode] 549. Binary Tree Longest Consecutive Sequence II

2018-09-17
阅读 2 分钟
2.9k
Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree.

[LeetCode] Path Sum (I & II & III)

2018-09-12
阅读 4 分钟
3.1k
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

[LintCode/LeetCode] Count Univalue Subtrees

2018-07-16
阅读 1 分钟
2.1k
A Uni-value subtree means all nodes of the subtree have the same value.

[LintCode/LeetCode] Binary Tree Pruning

2018-06-27
阅读 2 分钟
1.6k
Binary Tree PruningWe are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1.