1. Maximum Depth of Binary Tree(104)
二叉树的最大深度
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
|
|
2. Invert Binary Tree(226)
翻转二叉树
|
|
to
|
|
|
|
3. Same Tree(100)
相同二叉树
Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical and the nodes have the same value.
Example 1:
|
|
Example 2:
|
|
Example 3:
|
|
|
|
4. Symmetric Tree(101)
对称二叉树
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:
|
|
But the following [1,2,2,null,3,null,3] is not:
|
|
Note:
Bonus points if you could solve it both recursively and iteratively.
递归版
|
|
迭代版
|
|
5. Count Complete Tree Nodes(222)
完全二叉树
Given a complete binary tree, count the number of nodes.
|
|
6. Balanced Binary Tree(110)
平衡二叉树
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 differ by more than 1.
|
|
7. Path Sum(112)
根节点到叶节点的路径和
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.
For example:
Given the below binary tree and sum = 22,
|
|
eturn true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
|
|
8. Sum of Left Leaves(404)
二叉树左叶节点的和
Find the sum of all left leaves in a given binary tree.
Example:
|
|
9. Binary Tree Paths(257)
返回二叉树的路径
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
|
|
All root-to-leaf paths are:
|
|
|
|
10. Path Sum II(113)
Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.
For example:
Given the below binary tree and sum = 22,
|
|
return
|
|