From e2f9320e7dd7373cd59f047b393a681c9e100a6d Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Sat, 1 Nov 2025 14:00:18 +0700 Subject: [PATCH 1/3] Update readme for tasks 103-133 --- .../readme.md | 12 ------------ .../readme.md | 6 ++---- .../java/g0101_0200/s0112_path_sum/readme.md | 14 ++++++++++---- .../java/g0101_0200/s0120_triangle/readme.md | 9 +-------- .../readme.md | 2 +- .../readme.md | 4 ++-- .../readme.md | 8 +------- .../readme.md | 6 ++++++ .../s0130_surrounded_regions/readme.md | 18 ++++++++++++------ .../s0131_palindrome_partitioning/readme.md | 4 +--- .../g0101_0200/s0133_clone_graph/readme.md | 16 +--------------- 11 files changed, 37 insertions(+), 62 deletions(-) diff --git a/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md b/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md index aadf2c137..9d2b479c7 100644 --- a/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md +++ b/src/main/java/g0101_0200/s0104_maximum_depth_of_binary_tree/readme.md @@ -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 [0, 104]. diff --git a/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md b/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md index c5c6a1ef7..07e88db26 100644 --- a/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md +++ b/src/main/java/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/readme.md @@ -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:** @@ -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:** diff --git a/src/main/java/g0101_0200/s0112_path_sum/readme.md b/src/main/java/g0101_0200/s0112_path_sum/readme.md index 9402da46f..45f3df1e8 100644 --- a/src/main/java/g0101_0200/s0112_path_sum/readme.md +++ b/src/main/java/g0101_0200/s0112_path_sum/readme.md @@ -12,7 +12,9 @@ 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:** @@ -20,13 +22,17 @@ A **leaf** is a node with no children. **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:** diff --git a/src/main/java/g0101_0200/s0120_triangle/readme.md b/src/main/java/g0101_0200/s0120_triangle/readme.md index 3441abb92..d535afa48 100644 --- a/src/main/java/g0101_0200/s0120_triangle/readme.md +++ b/src/main/java/g0101_0200/s0120_triangle/readme.md @@ -12,14 +12,7 @@ For each step, you may move to an adjacent number of the row below. More formall **Output:** 11 -**Explanation:** - - The triangle looks like: - 2 - 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). +**Explanation:** The triangle looks like: 2 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). **Example 2:** diff --git a/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md b/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md index 1f99587fe..63c9bcd4a 100644 --- a/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md +++ b/src/main/java/g0101_0200/s0121_best_time_to_buy_and_sell_stock/readme.md @@ -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 ith 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. diff --git a/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md b/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md index 4b9c0d017..c3e347de1 100644 --- a/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md +++ b/src/main/java/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/readme.md @@ -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 ith 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_. diff --git a/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md b/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md index d70274771..ae6eeba33 100644 --- a/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md +++ b/src/main/java/g0101_0200/s0123_best_time_to_buy_and_sell_stock_iii/readme.md @@ -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 ith day. Find the maximum profit you can achieve. You may complete **at most two transactions**. @@ -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:** * 1 <= prices.length <= 105 diff --git a/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md b/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md index b22df106c..460a97646 100644 --- a/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md +++ b/src/main/java/g0101_0200/s0128_longest_consecutive_sequence/readme.md @@ -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:** * 0 <= nums.length <= 105 diff --git a/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md b/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md index 6b12aaacd..a0b0353b3 100644 --- a/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md +++ b/src/main/java/g0101_0200/s0130_surrounded_regions/readme.md @@ -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:** diff --git a/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md b/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md index 7da870e7b..a2c2f7757 100644 --- a/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md +++ b/src/main/java/g0101_0200/s0131_palindrome_partitioning/readme.md @@ -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:** diff --git a/src/main/java/g0101_0200/s0133_clone_graph/readme.md b/src/main/java/g0101_0200/s0133_clone_graph/readme.md index 97ec33204..a9493eaf6 100644 --- a/src/main/java/g0101_0200/s0133_clone_graph/readme.md +++ b/src/main/java/g0101_0200/s0133_clone_graph/readme.md @@ -26,13 +26,7 @@ The given node will always be the first node with `val = 1`. You must return the **Output:** [[2,4],[1,3],[2,4],[1,3]] -**Explanation:** - - There are 4 nodes in the graph. - 1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). - 2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). - 3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). - 4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). +**Explanation:** There are 4 nodes in the graph. 1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). 2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). 3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). 4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). **Example 2:** @@ -52,14 +46,6 @@ 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]`. From 5e448d0ab8acc353778cfccb3ac83b077f283423 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sat, 1 Nov 2025 09:32:29 +0200 Subject: [PATCH 2/3] Update readme.md --- src/main/java/g0101_0200/s0120_triangle/readme.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/g0101_0200/s0120_triangle/readme.md b/src/main/java/g0101_0200/s0120_triangle/readme.md index d535afa48..7cdd71a90 100644 --- a/src/main/java/g0101_0200/s0120_triangle/readme.md +++ b/src/main/java/g0101_0200/s0120_triangle/readme.md @@ -12,7 +12,14 @@ For each step, you may move to an adjacent number of the row below. More formall **Output:** 11 -**Explanation:** The triangle looks like: 2 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). +**Explanation:** + + The triangle looks like: + 2 + 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). **Example 2:** @@ -27,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` * -104 <= triangle[i][j] <= 104 -**Follow up:** Could you do this using only `O(n)` extra space, where `n` is the total number of rows in the triangle? \ No newline at end of file +**Follow up:** Could you do this using only `O(n)` extra space, where `n` is the total number of rows in the triangle? From dfac57c8b8c0c9f8744ca9d139c1d87cb5ee2625 Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sat, 1 Nov 2025 09:33:36 +0200 Subject: [PATCH 3/3] Update readme.md --- src/main/java/g0101_0200/s0133_clone_graph/readme.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/g0101_0200/s0133_clone_graph/readme.md b/src/main/java/g0101_0200/s0133_clone_graph/readme.md index a9493eaf6..8e5cdbfd1 100644 --- a/src/main/java/g0101_0200/s0133_clone_graph/readme.md +++ b/src/main/java/g0101_0200/s0133_clone_graph/readme.md @@ -26,7 +26,13 @@ The given node will always be the first node with `val = 1`. You must return the **Output:** [[2,4],[1,3],[2,4],[1,3]] -**Explanation:** There are 4 nodes in the graph. 1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). 2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). 3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). 4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). +**Explanation:** + + There are 4 nodes in the graph. + 1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). + 2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). + 3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4). + 4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3). **Example 2:** @@ -52,4 +58,4 @@ The given node will always be the first node with `val = 1`. You must return the * `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. \ No newline at end of file +* The Graph is connected and all nodes can be visited starting from the given node.