Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added descriptions 101-120.
  • Loading branch information
javadev committed Nov 21, 2021
commit 143d5a9de2ede4e5025c39e5683cf3d6cdac807c
28 changes: 28 additions & 0 deletions src/main/java/g0101_0200/s0101_symmetric_tree/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
101\. Symmetric Tree

Easy

Given the `root` of a binary tree, _check whether it is a mirror of itself_ (i.e., symmetric around its center).

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg)

**Input:** root = \[1,2,2,3,4,4,3\]

**Output:** true

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/02/19/symtree2.jpg)

**Input:** root = \[1,2,2,null,3,null,3\]

**Output:** false

**Constraints:**

* The number of nodes in the tree is in the range `[1, 1000]`.
* `-100 <= Node.val <= 100`

**Follow up:** Could you solve it both recursively and iteratively?
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
102\. Binary Tree Level Order Traversal

Medium

Given the `root` of a binary tree, return _the level order traversal of its nodes' values_. (i.e., from left to right, level by level).

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]

**Output:** \[\[3\],\[9,20\],\[15,7\]\]

**Example 2:**

**Input:** root = \[1\]

**Output:** \[\[1\]\]

**Example 3:**

**Input:** root = \[\]

**Output:** \[\]

**Constraints:**

* The number of nodes in the tree is in the range `[0, 2000]`.
* `-1000 <= Node.val <= 1000`
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
103\. Binary Tree Zigzag Level Order Traversal

Medium

Given the `root` of a binary tree, return _the zigzag level order traversal of its nodes' values_. (i.e., from left to right, then right to left for the next level and alternate between).

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]

**Output:** \[\[3\],\[20,9\],\[15,7\]\]

**Example 2:**

**Input:** root = \[1\]

**Output:** \[\[1\]\]

**Example 3:**

**Input:** root = \[\]

**Output:** \[\]

**Constraints:**

* The number of nodes in the tree is in the range `[0, 2000]`.
* `-100 <= Node.val <= 100`
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
104\. Maximum Depth of Binary Tree

Easy

Given the `root` of a binary tree, return _its maximum depth_.

A binary tree's **maximum depth** is the number of nodes along the longest path from the root node down to the farthest leaf node.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]

**Output:** 3

**Example 2:**

**Input:** root = \[1,null,2\]

**Output:** 2

**Example 3:**

**Input:** root = \[\]

**Output:** 0

**Example 4:**

**Input:** root = \[0\]

**Output:** 1

**Constraints:**

* The number of nodes in the tree is in the range `[0, 104]`.
* `-100 <= Node.val <= 100`
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
105\. Construct Binary Tree from Preorder and Inorder Traversal

Medium

Given two integer arrays `preorder` and `inorder` where `preorder` is the preorder traversal of a binary tree and `inorder` is the inorder traversal of the same tree, construct and return _the binary tree_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/19/tree.jpg)

**Input:** preorder = \[3,9,20,15,7\], inorder = \[9,3,15,20,7\]

**Output:** \[3,9,20,null,null,15,7\]

**Example 2:**

**Input:** preorder = \[-1\], inorder = \[-1\]

**Output:** \[-1\]

**Constraints:**

* `1 <= preorder.length <= 3000`
* `inorder.length == preorder.length`
* `-3000 <= preorder[i], inorder[i] <= 3000`
* `preorder` and `inorder` consist of **unique** values.
* Each value of `inorder` also appears in `preorder`.
* `preorder` is **guaranteed** to be the preorder traversal of the tree.
* `inorder` is **guaranteed** to be the inorder traversal of the tree.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
106\. Construct Binary Tree from Inorder and Postorder Traversal

Medium

Given two integer arrays `inorder` and `postorder` where `inorder` is the inorder traversal of a binary tree and `postorder` is the postorder traversal of the same tree, construct and return _the binary tree_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/19/tree.jpg)

**Input:** inorder = \[9,3,15,20,7\], postorder = \[9,15,7,20,3\]

**Output:** \[3,9,20,null,null,15,7\]

**Example 2:**

**Input:** inorder = \[-1\], postorder = \[-1\]

**Output:** \[-1\]

**Constraints:**

* `1 <= inorder.length <= 3000`
* `postorder.length == inorder.length`
* `-3000 <= inorder[i], postorder[i] <= 3000`
* `inorder` and `postorder` consist of **unique** values.
* Each value of `postorder` also appears in `inorder`.
* `inorder` is **guaranteed** to be the inorder traversal of the tree.
* `postorder` is **guaranteed** to be the postorder traversal of the tree.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
107\. Binary Tree Level Order Traversal II

Medium

Given the `root` of a binary tree, return _the bottom-up level order traversal of its nodes' values_. (i.e., from left to right, level by level from leaf to root).

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]

**Output:** \[\[15,7\],\[9,20\],\[3\]\]

**Example 2:**

**Input:** root = \[1\]

**Output:** \[\[1\]\]

**Example 3:**

**Input:** root = \[\]

**Output:** \[\]

**Constraints:**

* The number of nodes in the tree is in the range `[0, 2000]`.
* `-1000 <= Node.val <= 1000`
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
108\. Convert Sorted Array to Binary Search Tree

Easy

Given an integer array `nums` where the elements are sorted in **ascending order**, convert _it to a **height-balanced** binary search tree_.

A **height-balanced** binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/02/18/btree1.jpg)

**Input:** nums = \[-10,-3,0,5,9\]

**Output:** \[0,-3,9,-10,null,5\]

**Explanation:** \[0,-10,5,null,-3,null,9\] is also accepted: ![](https://assets.leetcode.com/uploads/2021/02/18/btree2.jpg)

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/02/18/btree.jpg)

**Input:** nums = \[1,3\]

**Output:** \[3,1\]

**Explanation:** \[1,3\] and \[3,1\] are both a height-balanced BSTs.

**Constraints:**

* `1 <= nums.length <= 104`
* `-104 <= nums[i] <= 104`
* `nums` is sorted in a **strictly increasing** order.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
109\. Convert Sorted List to Binary Search Tree

Medium

Given the `head` of a singly linked list where elements are **sorted in ascending order**, convert it to a height balanced BST.

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.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/08/17/linked.jpg)

**Input:** head = \[-10,-3,0,5,9\]

**Output:** \[0,-3,9,-10,null,5\]

**Explanation:** One possible answer is \[0,-3,9,-10,null,5\], which represents the shown height balanced BST.

**Example 2:**

**Input:** head = \[\]

**Output:** \[\]

**Example 3:**

**Input:** head = \[0\]

**Output:** \[0\]

**Example 4:**

**Input:** head = \[1,3\]

**Output:** \[3,1\]

**Constraints:**

* The number of nodes in `head` is in the range `[0, 2 * 104]`.
* `-105 <= Node.val <= 105`
36 changes: 36 additions & 0 deletions src/main/java/g0101_0200/s0110_balanced_binary_tree/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
110\. Balanced Binary Tree

Easy

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 left and right subtrees of _every_ node differ in height by no more than 1.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/10/06/balance_1.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]

**Output:** true

**Example 2:**

![](https://assets.leetcode.com/uploads/2020/10/06/balance_2.jpg)

**Input:** root = \[1,2,2,3,3,null,null,4,4\]

**Output:** false

**Example 3:**

**Input:** root = \[\]

**Output:** true

**Constraints:**

* The number of nodes in the tree is in the range `[0, 5000]`.
* `-104 <= Node.val <= 104`
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
111\. Minimum Depth of Binary Tree

Easy

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:**

![](https://assets.leetcode.com/uploads/2020/10/12/ex_depth.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]

**Output:** 2

**Example 2:**

**Input:** root = \[2,null,3,null,4,null,5,null,6\]

**Output:** 5

**Constraints:**

* The number of nodes in the tree is in the range `[0, 105]`.
* `-1000 <= Node.val <= 1000`
Loading