Skip to main content
559, Maximum Depth of N-ary Tree

I Problem

Given a n-ary 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.

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).


MikeAbout 3 minbinary treeeasytreedepth first searchbreadth first search
100, Same Tree

I Problem

Given the roots of two binary trees p and q, 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

Input: p = [1, 2, 3], q = [1, 2, 3]
Output: true


MikeAbout 2 minbinary treeeasybinary treedepth first searchbreadth first search
530, Minimum Absolute Difference in BST

I Problem

Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.

Example 1

Input: root = [4, 2, 6, 1, 3]
Output: 1

Example 2

Input: root = [1, 0, 48, null, null, 12, 49]
Output: 1


MikeAbout 2 minbinary treeeasybinary treebinary search treedepth first searchbreadth first search
617, Merge Two Binary Trees

I Problem

You are given two binary trees root1 and root2.

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. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree.


MikeAbout 5 minbinary treeeasybinary treedepth first searchbreadth first search
226, Invert Binary Tree

I Problem

Given the root of a binary tree, invert the tree, and return its root.

Example 1

Input: root = [4, 2, 7, 1, 3, 6, 9]
Output: [4, 7, 2, 9, 6, 3, 1]

Example 2

Input: root = [2, 1, 3]
Output: [2, 3, 1]


MikeAbout 2 minbinary treeeasybinary treedepth first searchbreadth first search
113, Path Sum II

I Problem

Given the root of a binary tree and an integer target_sum, return all root-to-leaf paths where the sum of the node values in the path equals target_sum. Each path should be returned as a list of the node values, not node references.


MikeAbout 4 minbinary treemediumbacktrackingbinary treedepth first searchbreadth first search
112, Path Sum

I Problem

Given the root of a binary tree and an integer target_sum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals target_sum.

A leaf is a node with no children.


MikeAbout 5 minbinary treeeasybinary treedepth first searchbreadth first search
513, Find Bottom Left Tree Value

I Problem

Given the root of a binary tree, return the leftmost value in the last row of the tree.

Example 1

Input: root = [2, 1, 3]
Output: 1

Example 2

Input: root = [1, 2, 3, 4, null, 5, 6, null, null, 7]
Output: 7


MikeAbout 3 minbinary treemediumbinary treedepth first searchbreadth first search
404, Sum of Left Leaves

I Problem

Given the root of a binary tree, return the sum of all left leaves.

A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

Example 1

Input: root = [3, 9, 20, null, null, 15, 7]
Output: 24
Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.


MikeAbout 3 minbinary treeeasybinary treedepth first searchbreadth first search
111, Minimum Depth of Binary Tree

I Problem

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Note: A leaf is a node with no children.

Example 1

Input: root = [3, 9, 20, null, null, 15, 7]
Output: 2


MikeAbout 3 minbinary treeeasybinary treedepth first searchbreadth first search
2