From f1fef9eaf2304d52aa148000460a39a2dff6a9e2 Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Sun, 2 Nov 2025 21:52:13 +0700 Subject: [PATCH] Update readme for tasks 219-300 --- .../s0219_contains_duplicate_ii/readme.md | 2 +- .../s0222_count_complete_tree_nodes/readme.md | 2 +- .../g0201_0300/s0228_summary_ranges/readme.md | 20 ++------------ .../s0234_palindrome_linked_list/readme.md | 2 +- .../readme.md | 4 +-- .../s0239_sliding_window_maximum/readme.md | 18 ------------- .../s0240_search_a_2d_matrix_ii/readme.md | 2 +- .../g0201_0300/s0242_valid_anagram/readme.md | 6 ++--- .../java/g0201_0300/s0274_h_index/readme.md | 13 +++------ .../s0287_find_the_duplicate_number/readme.md | 12 +++------ .../g0201_0300/s0289_game_of_life/readme.md | 10 ++++--- .../g0201_0300/s0290_word_pattern/readme.md | 27 +++++++++++-------- .../readme.md | 2 +- .../readme.md | 4 +-- 14 files changed, 43 insertions(+), 81 deletions(-) diff --git a/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md b/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md index 227015fc0..3ac510266 100644 --- a/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md +++ b/src/main/java/g0201_0300/s0219_contains_duplicate_ii/readme.md @@ -2,7 +2,7 @@ Easy -Given an integer array `nums` and an integer `k`, return `true` if there are two **distinct indices** `i` and `j` in the array such that `nums[i] == nums[j]` and `abs(i - j) <= k`. +Given an integer array `nums` and an integer `k`, return `true` _if there are two **distinct indices**_ `i` _and_ `j` _in the array such that_ `nums[i] == nums[j]` _and_ `abs(i - j) <= k`. **Example 1:** diff --git a/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md b/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md index 60b870acc..52180e015 100644 --- a/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md +++ b/src/main/java/g0201_0300/s0222_count_complete_tree_nodes/readme.md @@ -1,6 +1,6 @@ 222\. Count Complete Tree Nodes -Medium +Easy Given the `root` of a **complete** binary tree, return the number of the nodes in the tree. diff --git a/src/main/java/g0201_0300/s0228_summary_ranges/readme.md b/src/main/java/g0201_0300/s0228_summary_ranges/readme.md index d7c4ae981..e0dd913e9 100644 --- a/src/main/java/g0201_0300/s0228_summary_ranges/readme.md +++ b/src/main/java/g0201_0300/s0228_summary_ranges/readme.md @@ -4,6 +4,8 @@ Easy You are given a **sorted unique** integer array `nums`. +A **range** `[a,b]` is the set of all integers from `a` to `b` (inclusive). + Return _the **smallest sorted** list of ranges that **cover all the numbers in the array exactly**_. That is, each element of `nums` is covered by exactly one of the ranges, and there is no integer `x` such that `x` is in one of the ranges but not in `nums`. Each range `[a,b]` in the list should be output as: @@ -27,24 +29,6 @@ Each range `[a,b]` in the list should be output as: **Explanation:** The ranges are: [0,0] --> "0" [2,4] --> "2->4" [6,6] --> "6" [8,9] --> "8->9" -**Example 3:** - -**Input:** nums = [] - -**Output:** [] - -**Example 4:** - -**Input:** nums = [-1] - -**Output:** ["-1"] - -**Example 5:** - -**Input:** nums = [0] - -**Output:** ["0"] - **Constraints:** * `0 <= nums.length <= 20` diff --git a/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md b/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md index 096f4015e..0293ad232 100644 --- a/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md +++ b/src/main/java/g0201_0300/s0234_palindrome_linked_list/readme.md @@ -2,7 +2,7 @@ Easy -Given the `head` of a singly linked list, return `true` if it is a palindrome. +Given the `head` of a singly linked list, return `true` _if it is a_ _palindrome_ _or_ `false` _otherwise_. **Example 1:** diff --git a/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md b/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md index aad514d63..33cd79e48 100644 --- a/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md +++ b/src/main/java/g0201_0300/s0238_product_of_array_except_self/readme.md @@ -24,6 +24,6 @@ You must write an algorithm that runs in `O(n)` time and without using the divis * 2 <= nums.length <= 105 * `-30 <= nums[i] <= 30` -* The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. +* The input is generated such that `answer[i]` is **guaranteed** to fit in a **32-bit** integer. -**Follow up:** Can you solve the problem in `O(1) `extra space complexity? (The output array **does not** count as extra space for space complexity analysis.) \ No newline at end of file +**Follow up:** Can you solve the problem in `O(1)` extra space complexity? (The output array **does not** count as extra space for space complexity analysis.) \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md b/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md index e56687482..ff6f98e93 100644 --- a/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md +++ b/src/main/java/g0201_0300/s0239_sliding_window_maximum/readme.md @@ -29,24 +29,6 @@ Return _the max sliding window_. **Output:** [1] -**Example 3:** - -**Input:** nums = [1,-1], k = 1 - -**Output:** [1,-1] - -**Example 4:** - -**Input:** nums = [9,11], k = 2 - -**Output:** [11] - -**Example 5:** - -**Input:** nums = [4,-2], k = 2 - -**Output:** [4] - **Constraints:** * 1 <= nums.length <= 105 diff --git a/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md b/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md index 2e111b7c6..113883ea3 100644 --- a/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md +++ b/src/main/java/g0201_0300/s0240_search_a_2d_matrix_ii/readme.md @@ -2,7 +2,7 @@ Medium -Write an efficient algorithm that searches for a `target` value in an `m x n` integer `matrix`. The `matrix` has the following properties: +Write an efficient algorithm that searches for a value `target` in an `m x n` integer matrix `matrix`. This matrix has the following properties: * Integers in each row are sorted in ascending from left to right. * Integers in each column are sorted in ascending from top to bottom. diff --git a/src/main/java/g0201_0300/s0242_valid_anagram/readme.md b/src/main/java/g0201_0300/s0242_valid_anagram/readme.md index ec6cd2c0d..5e596297e 100644 --- a/src/main/java/g0201_0300/s0242_valid_anagram/readme.md +++ b/src/main/java/g0201_0300/s0242_valid_anagram/readme.md @@ -2,19 +2,19 @@ Easy -Given two strings `s` and `t`, return `true` _if_ `t` _is an anagram of_ `s`_, and_ `false` _otherwise_. +Given two strings `s` and `t`, return `true` if `t` is an anagram of `s`, and `false` otherwise. **Example 1:** **Input:** s = "anagram", t = "nagaram" -**Output:** true +**Output:** true **Example 2:** **Input:** s = "rat", t = "car" -**Output:** false +**Output:** false **Constraints:** diff --git a/src/main/java/g0201_0300/s0274_h_index/readme.md b/src/main/java/g0201_0300/s0274_h_index/readme.md index 73d5909ae..54674df27 100644 --- a/src/main/java/g0201_0300/s0274_h_index/readme.md +++ b/src/main/java/g0201_0300/s0274_h_index/readme.md @@ -2,11 +2,9 @@ Medium -Given an array of integers `citations` where `citations[i]` is the number of citations a researcher received for their ith paper, return compute the researcher's `h`**\-index**. +Given an array of integers `citations` where `citations[i]` is the number of citations a researcher received for their ith paper, return _the researcher's h-index_. -According to the [definition of h-index on Wikipedia](https://en.wikipedia.org/wiki/H-index): A scientist has an index `h` if `h` of their `n` papers have at least `h` citations each, and the other `n − h` papers have no more than `h` citations each. - -If there are several possible values for `h`, the maximum one is taken as the `h`**\-index**. +According to the [definition of h-index on Wikipedia](https://en.wikipedia.org/wiki/H-index): The h-index is defined as the maximum value of `h` such that the given researcher has published at least `h` papers that have each been cited at least `h` times. **Example 1:** @@ -14,10 +12,7 @@ If there are several possible values for `h`, the maximum one is taken as the `h **Output:** 3 -**Explanation:** - - [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. - Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3. +**Explanation:** [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3. **Example 2:** @@ -29,4 +24,4 @@ If there are several possible values for `h`, the maximum one is taken as the `h * `n == citations.length` * `1 <= n <= 5000` -* `0 <= citations[i] <= 1000` +* `0 <= citations[i] <= 1000` \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md b/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md index fddfbbb90..80f34a277 100644 --- a/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md +++ b/src/main/java/g0201_0300/s0287_find_the_duplicate_number/readme.md @@ -6,7 +6,7 @@ Given an array of integers `nums` containing `n + 1` integers where each integer There is only **one repeated number** in `nums`, return _this repeated number_. -You must solve the problem **without** modifying the array `nums` and uses only constant extra space. +You must solve the problem **without** modifying the array `nums` and using only constant extra space. **Example 1:** @@ -22,15 +22,9 @@ You must solve the problem **without** modifying the array `nums` and uses only **Example 3:** -**Input:** nums = [1,1] +**Input:** nums = [3,3,3,3,3] -**Output:** 1 - -**Example 4:** - -**Input:** nums = [1,1,2] - -**Output:** 1 +**Output:** 3 **Constraints:** diff --git a/src/main/java/g0201_0300/s0289_game_of_life/readme.md b/src/main/java/g0201_0300/s0289_game_of_life/readme.md index f54ef7a0b..2f7da08ad 100644 --- a/src/main/java/g0201_0300/s0289_game_of_life/readme.md +++ b/src/main/java/g0201_0300/s0289_game_of_life/readme.md @@ -11,7 +11,11 @@ The board is made up of an `m x n` grid of cells, where each cell has an initial 3. Any live cell with more than three live neighbors dies, as if by over-population. 4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. -The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously. Given the current state of the `m x n` grid `board`, return _the next state_. +The next state of the board is determined by applying the above rules simultaneously to every cell in the current state of the `m x n` grid `board`. In this process, births and deaths occur **simultaneously**. + +Given the current state of the `board`, **update** the `board` to reflect its next state. + +**Note** that you do not need to return anything. **Example 1:** @@ -19,7 +23,7 @@ The next state is created by applying the above rules simultaneously to every ce **Input:** board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]] -**Output:** [[0,0,0],[1,0,1],[0,1,1],[0,1,0]] +**Output:** [[0,0,0],[1,0,1],[0,1,1],[0,1,0]] **Example 2:** @@ -27,7 +31,7 @@ The next state is created by applying the above rules simultaneously to every ce **Input:** board = [[1,1],[1,0]] -**Output:** [[1,1],[1,1]] +**Output:** [[1,1],[1,1]] **Constraints:** diff --git a/src/main/java/g0201_0300/s0290_word_pattern/readme.md b/src/main/java/g0201_0300/s0290_word_pattern/readme.md index b0a003116..0d8303693 100644 --- a/src/main/java/g0201_0300/s0290_word_pattern/readme.md +++ b/src/main/java/g0201_0300/s0290_word_pattern/readme.md @@ -4,37 +4,42 @@ Easy Given a `pattern` and a string `s`, find if `s` follows the same pattern. -Here **follow** means a full match, such that there is a bijection between a letter in `pattern` and a **non-empty** word in `s`. +Here **follow** means a full match, such that there is a bijection between a letter in `pattern` and a **non-empty** word in `s`. Specifically: + +* Each letter in `pattern` maps to **exactly** one unique word in `s`. +* Each unique word in `s` maps to **exactly** one letter in `pattern`. +* No two letters map to the same word, and no two words map to the same letter. **Example 1:** **Input:** pattern = "abba", s = "dog cat cat dog" -**Output:** true +**Output:** true + +**Explanation:** + +The bijection can be established as: + +* `'a'` maps to `"dog"`. +* `'b'` maps to `"cat"`. **Example 2:** **Input:** pattern = "abba", s = "dog cat cat fish" -**Output:** false +**Output:** false **Example 3:** **Input:** pattern = "aaaa", s = "dog cat cat dog" -**Output:** false - -**Example 4:** - -**Input:** pattern = "abba", s = "dog dog dog dog" - -**Output:** false +**Output:** false **Constraints:** * `1 <= pattern.length <= 300` * `pattern` contains only lower-case English letters. * `1 <= s.length <= 3000` -* `s` contains only lower-case English letters and spaces `' '`. +* `s` contains only lowercase English letters and spaces `' '`. * `s` **does not contain** any leading or trailing spaces. * All the words in `s` are separated by a **single space**. \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md b/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md index 3928225f2..e7f1e8cb5 100644 --- a/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md +++ b/src/main/java/g0201_0300/s0295_find_median_from_data_stream/readme.md @@ -2,7 +2,7 @@ Hard -The **median** is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. +The **median** is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values. * For example, for `arr = [2,3,4]`, the median is `3`. * For example, for `arr = [2,3]`, the median is `(2 + 3) / 2 = 2.5`. diff --git a/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md b/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md index 4b09231aa..90f97daec 100644 --- a/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md +++ b/src/main/java/g0201_0300/s0300_longest_increasing_subsequence/readme.md @@ -2,9 +2,7 @@ Medium -Given an integer array `nums`, return the length of the longest strictly increasing subsequence. - -A **subsequence** is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, `[3,6,2,7]` is a subsequence of the array `[0,3,1,6,2,2,7]`. +Given an integer array `nums`, return _the length of the longest **strictly increasing**_ **subsequences**. **Example 1:**