Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ A binary tree's **maximum depth** is the number of nodes along the longest path

**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 <code>[0, 10<sup>4</sup>]</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

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.
Given an integer array `nums` where the elements are sorted in **ascending order**, convert _it to a_ **_height-balanced_** _binary search tree_.

**Example 1:**

Expand All @@ -24,7 +22,7 @@ A **height-balanced** binary tree is a binary tree in which the depth of the two

**Output:** [3,1]

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

**Constraints:**

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/g0101_0200/s0112_path_sum/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ A **leaf** is a node with no children.

**Input:** root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22

**Output:** true
**Output:** true

**Explanation:** The root-to-leaf path with the target sum is shown.

**Example 2:**

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

**Input:** root = [1,2,3], targetSum = 5

**Output:** false
**Output:** false

**Explanation:** There are two root-to-leaf paths in the tree: (1 --> 2): The sum is 3. (1 --> 3): The sum is 4. There is no root-to-leaf path with sum = 5.

**Example 3:**

**Input:** root = [1,2], targetSum = 0
**Input:** root = [], targetSum = 0

**Output:** false

**Output:** false
**Explanation:** Since the tree is empty, there are no root-to-leaf paths.

**Constraints:**

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/g0101_0200/s0120_triangle/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For each step, you may move to an adjacent number of the row below. More formall
3 4
6 5 7
4 1 8 3
The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).

**Example 2:**

Expand All @@ -34,4 +34,4 @@ For each step, you may move to an adjacent number of the row below. More formall
* `triangle[i].length == triangle[i - 1].length + 1`
* <code>-10<sup>4</sup> <= triangle[i][j] <= 10<sup>4</sup></code>

**Follow up:** Could you do this using only `O(n)` extra space, where `n` is the total number of rows in the triangle?
**Follow up:** Could you do this using only `O(n)` extra space, where `n` is the total number of rows in the triangle?
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Easy

You are given an array `prices` where `prices[i]` is the price of a given stock on the `ith` day.
You are given an array `prices` where `prices[i]` is the price of a given stock on the <code>i<sup>th</sup></code> day.

You want to maximize your profit by choosing a **single day** to buy one stock and choosing a **different day in the future** to sell that stock.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Medium

You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day.
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the <code>i<sup>th</sup></code> day.

On each day, you may decide to buy and/or sell the stock. You can only hold **at most one** share of the stock at any time. However, you can buy it then immediately sell it on the **same day**.
On each day, you may decide to buy and/or sell the stock. You can only hold **at most one** share of the stock at any time. However, you can sell and buy the stock multiple times on the **same day**, ensuring you never hold more than one share of the stock.

Find and return _the **maximum** profit you can achieve_.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Hard

You are given an array `prices` where `prices[i]` is the price of a given stock on the `ith` day.
You are given an array `prices` where `prices[i]` is the price of a given stock on the <code>i<sup>th</sup></code> day.

Find the maximum profit you can achieve. You may complete **at most two transactions**.

Expand Down Expand Up @@ -32,12 +32,6 @@ Find the maximum profit you can achieve. You may complete **at most two transact

**Explanation:** In this case, no transaction is done, i.e. max profit = 0.

**Example 4:**

**Input:** prices = [1]

**Output:** 0

**Constraints:**

* <code>1 <= prices.length <= 10<sup>5</sup></code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ You must write an algorithm that runs in `O(n)` time.

**Output:** 9

**Example 3:**

**Input:** nums = [1,0,1,2]

**Output:** 3

**Constraints:**

* <code>0 <= nums.length <= 10<sup>5</sup></code>
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/g0101_0200/s0130_surrounded_regions/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@

Medium

Given an `m x n` matrix `board` containing `'X'` and `'O'`, _capture all regions that are 4-directionally surrounded by_ `'X'`.
You are given an `m x n` matrix `board` containing **letters** `'X'` and `'O'`, **capture regions** that are **surrounded**:

A region is **captured** by flipping all `'O'`s into `'X'`s in that surrounded region.
* **Connect**: A cell is connected to adjacent cells horizontally or vertically.
* **Region**: To form a region **connect every** `'O'` cell.
* **Surround**: The region is surrounded with `'X'` cells if you can **connect the region** with `'X'` cells and none of the region cells are on the edge of the `board`.

**Example 1:**
To capture a **surrounded region**, replace all `'O'`s with `'X'`s **in-place** within the original board. You do not need to return anything.

![](https://assets.leetcode.com/uploads/2021/02/19/xogrid.jpg)
**Example 1:**

**Input:** board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]

**Output:** [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]

**Explanation:** Surrounded regions should not be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically.
**Explanation:**

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

In the above diagram, the bottom region is not captured because it is on the edge of the board and cannot be surrounded.

**Example 2:**

**Input:** board = [["X"]]

**Output:** [["X"]]
**Output:** [["X"]]

**Constraints:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

Medium

Given a string `s`, partition `s` such that every substring of the partition is a **palindrome**. Return all possible palindrome partitioning of `s`.

A **palindrome** string is a string that reads the same backward as forward.
Given a string `s`, partition `s` such that every **substring** of the partition is a **palindrome**. Return _all possible palindrome partitioning of_ `s`.

**Example 1:**

Expand Down
10 changes: 1 addition & 9 deletions src/main/java/g0101_0200/s0133_clone_graph/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,10 @@ The given node will always be the first node with `val = 1`. You must return the

**Explanation:** This an empty graph, it does not have any nodes.

**Example 4:**

![](https://assets.leetcode.com/uploads/2020/01/07/graph-1.png)

**Input:** adjList = [[2],[1]]

**Output:** [[2],[1]]

**Constraints:**

* The number of nodes in the graph is in the range `[0, 100]`.
* `1 <= Node.val <= 100`
* `Node.val` is unique for each node.
* There are no repeated edges and no self-loops in the graph.
* The Graph is connected and all nodes can be visited starting from the given node.
* The Graph is connected and all nodes can be visited starting from the given node.