From 10bfdcc64e59673bbb7711f7e81769e70d3a59b9 Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Mon, 3 Nov 2025 19:47:56 +0700 Subject: [PATCH] update readme for tasks 322-1143 --- .../s0347_top_k_frequent_elements/readme.md | 7 +++++++ .../readme.md | 19 ++++++------------ .../readme.md | 2 +- .../g0301_0400/s0383_ransom_note/readme.md | 8 ++++---- .../g0301_0400/s0392_is_subsequence/readme.md | 6 +++--- .../g0301_0400/s0394_decode_string/readme.md | 10 ++-------- .../s0399_evaluate_division/readme.md | 6 ++++-- .../readme.md | 2 +- .../s0427_construct_quad_tree/readme.md | 10 ++++------ .../s0433_minimum_genetic_mutation/readme.md | 20 ++++++------------- .../readme.md | 6 ++---- .../s0560_subarray_sum_equals_k/readme.md | 4 +++- .../readme.md | 4 ++-- .../s0763_partition_labels/readme.md | 10 ++++------ .../s0909_snakes_and_ladders/readme.md | 12 +++++------ 15 files changed, 55 insertions(+), 71 deletions(-) diff --git a/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md b/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md index 9e5239fd7..57fa49510 100644 --- a/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md +++ b/src/main/java/g0301_0400/s0347_top_k_frequent_elements/readme.md @@ -16,9 +16,16 @@ Given an integer array `nums` and an integer `k`, return _the_ `k` _most frequen **Output:** [1] +**Example 3:** + +**Input:** nums = [1,2,1,2,1,2,3,1,3,2], k = 2 + +**Output:** [1,2] + **Constraints:** * 1 <= nums.length <= 105 +* -104 <= nums[i] <= 104 * `k` is in the range `[1, the number of unique elements in the array]`. * It is **guaranteed** that the answer is **unique**. diff --git a/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md b/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md index eba0c310d..0b08c05a3 100644 --- a/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md +++ b/src/main/java/g0301_0400/s0373_find_k_pairs_with_smallest_sums/readme.md @@ -2,7 +2,7 @@ Medium -You are given two integer arrays `nums1` and `nums2` sorted in **ascending order** and an integer `k`. +You are given two integer arrays `nums1` and `nums2` sorted in **non-decreasing order** and an integer `k`. Define a pair `(u, v)` which consists of one element from the first array and one element from the second array. @@ -14,7 +14,7 @@ Return _the_ `k` _pairs_ (u1, v1), (u2, v **Output:** [[1,2],[1,4],[1,6]] -**Explanation:** The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6] +**Explanation:** The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6] **Example 2:** @@ -22,19 +22,12 @@ Return _the_ `k` _pairs_ (u1, v1), (u2, v **Output:** [[1,1],[1,1]] -**Explanation:** The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3] - -**Example 3:** - -**Input:** nums1 = [1,2], nums2 = [3], k = 3 - -**Output:** [[1,3],[2,3]] - -**Explanation:** All possible pairs are returned from the sequence: [1,3],[2,3] +**Explanation:** The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3] **Constraints:** * 1 <= nums1.length, nums2.length <= 105 * -109 <= nums1[i], nums2[i] <= 109 -* `nums1` and `nums2` both are sorted in **ascending order**. -* `1 <= k <= 1000` \ No newline at end of file +* `nums1` and `nums2` both are sorted in **non-decreasing order**. +* 1 <= k <= 104 +* `k <= nums1.length * nums2.length` \ No newline at end of file diff --git a/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md b/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md index 7e2c59116..63a824c0d 100644 --- a/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md +++ b/src/main/java/g0301_0400/s0380_insert_delete_getrandom_o1/readme.md @@ -35,4 +35,4 @@ You must implement the functions of the class such that each function works in * * -231 <= val <= 231 - 1 * At most `2 * `105 calls will be made to `insert`, `remove`, and `getRandom`. -* There will be **at least one** element in the data structure when `getRandom` is called. +* There will be **at least one** element in the data structure when `getRandom` is called. \ No newline at end of file diff --git a/src/main/java/g0301_0400/s0383_ransom_note/readme.md b/src/main/java/g0301_0400/s0383_ransom_note/readme.md index 63348ff02..57f5e85d6 100644 --- a/src/main/java/g0301_0400/s0383_ransom_note/readme.md +++ b/src/main/java/g0301_0400/s0383_ransom_note/readme.md @@ -2,7 +2,7 @@ Easy -Given two stings `ransomNote` and `magazine`, return `true` if `ransomNote` can be constructed from `magazine` and `false` otherwise. +Given two strings `ransomNote` and `magazine`, return `true` _if_ `ransomNote` _can be constructed by using the letters from_ `magazine` _and_ `false` _otherwise_. Each letter in `magazine` can only be used once in `ransomNote`. @@ -10,19 +10,19 @@ Each letter in `magazine` can only be used once in `ransomNote`. **Input:** ransomNote = "a", magazine = "b" -**Output:** false +**Output:** false **Example 2:** **Input:** ransomNote = "aa", magazine = "ab" -**Output:** false +**Output:** false **Example 3:** **Input:** ransomNote = "aa", magazine = "aab" -**Output:** true +**Output:** true **Constraints:** diff --git a/src/main/java/g0301_0400/s0392_is_subsequence/readme.md b/src/main/java/g0301_0400/s0392_is_subsequence/readme.md index a002fe06d..526536c97 100644 --- a/src/main/java/g0301_0400/s0392_is_subsequence/readme.md +++ b/src/main/java/g0301_0400/s0392_is_subsequence/readme.md @@ -4,19 +4,19 @@ Easy Given two strings `s` and `t`, return `true` _if_ `s` _is a **subsequence** of_ `t`_, or_ `false` _otherwise_. -A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace"` is a subsequence of `"abcde"` while `"aec"` is not). +A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace"` is a subsequence of "abcde" while `"aec"` is not). **Example 1:** **Input:** s = "abc", t = "ahbgdc" -**Output:** true +**Output:** true **Example 2:** **Input:** s = "axc", t = "ahbgdc" -**Output:** false +**Output:** false **Constraints:** diff --git a/src/main/java/g0301_0400/s0394_decode_string/readme.md b/src/main/java/g0301_0400/s0394_decode_string/readme.md index 7c0a9e7f4..56bc3294b 100644 --- a/src/main/java/g0301_0400/s0394_decode_string/readme.md +++ b/src/main/java/g0301_0400/s0394_decode_string/readme.md @@ -6,9 +6,9 @@ Given an encoded string, return its decoded string. The encoding rule is: `k[encoded_string]`, where the `encoded_string` inside the square brackets is being repeated exactly `k` times. Note that `k` is guaranteed to be a positive integer. -You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc. +You may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there will not be input like `3a` or `2[4]`. -Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, `k`. For example, there won't be input like `3a` or `2[4]`. +The test cases are generated so that the length of the output will never exceed 105. **Example 1:** @@ -28,12 +28,6 @@ Furthermore, you may assume that the original data does not contain any digits a **Output:** "abcabccdcdcdef" -**Example 4:** - -**Input:** s = "abc3[cd]xyz" - -**Output:** "abccdcdcdxyz" - **Constraints:** * `1 <= s.length <= 30` diff --git a/src/main/java/g0301_0400/s0399_evaluate_division/readme.md b/src/main/java/g0301_0400/s0399_evaluate_division/readme.md index 18a83c514..bbf9ca85d 100644 --- a/src/main/java/g0301_0400/s0399_evaluate_division/readme.md +++ b/src/main/java/g0301_0400/s0399_evaluate_division/readme.md @@ -10,6 +10,8 @@ Return _the answers to all queries_. If a single answer cannot be determined, re **Note:** The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction. +**Note:** The variables that do not occur in the list of equations are undefined, so the answer cannot be determined for them. + **Example 1:** **Input:** equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] @@ -28,13 +30,13 @@ return: [6.0, 0.5, -1.0, 1.0, -1.0 ] **Input:** equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]] -**Output:** [3.75000,0.40000,5.00000,0.20000] +**Output:** [3.75000,0.40000,5.00000,0.20000] **Example 3:** **Input:** equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]] -**Output:** [0.50000,2.00000,-1.00000,-1.00000] +**Output:** [0.50000,2.00000,-1.00000,-1.00000] **Constraints:** diff --git a/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md b/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md index 56f915ce5..ec00c4fc4 100644 --- a/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md +++ b/src/main/java/g0401_0500/s0416_partition_equal_subset_sum/readme.md @@ -2,7 +2,7 @@ Medium -Given a **non-empty** array `nums` containing **only positive integers**, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. +Given an integer array `nums`, return `true` _if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or_ `false` _otherwise_. **Example 1:** diff --git a/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md b/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md index 9e9dd3d1f..67ee6a948 100644 --- a/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md +++ b/src/main/java/g0401_0500/s0427_construct_quad_tree/readme.md @@ -2,11 +2,9 @@ Medium -Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent the `grid` with a Quad-Tree. +Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent `grid` with a Quad-Tree. -Return _the root of the Quad-Tree_ representing the `grid`. - -Notice that you can assign the value of a node to **True** or **False** when `isLeaf` is **False**, and both are **accepted** in the answer. +Return _the root of the Quad-Tree representing_ `grid`. A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes: @@ -34,7 +32,7 @@ If you want to know more about the Quad-Tree, you can refer to the [wiki](https: **Quad-Tree format:** -The output represents the serialized format of a Quad-Tree using level order traversal, where `null` signifies a path terminator where no node exists below. +You don't need to read this section for solving the problem. This is only if you want to understand the output format here. The output represents the serialized format of a Quad-Tree using level order traversal, where `null` signifies a path terminator where no node exists below. It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list `[isLeaf, val]`. @@ -75,4 +73,4 @@ If the value of `isLeaf` or `val` is True we represent it as **1** in the list ` **Constraints:** * `n == grid.length == grid[i].length` -* n == 2x where `0 <= x <= 6` +* n == 2x where `0 <= x <= 6` \ No newline at end of file diff --git a/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md b/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md index fa7b3817b..d41f976b3 100644 --- a/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md +++ b/src/main/java/g0401_0500/s0433_minimum_genetic_mutation/readme.md @@ -4,38 +4,30 @@ Medium A gene string can be represented by an 8-character long string, with choices from `'A'`, `'C'`, `'G'`, and `'T'`. -Suppose we need to investigate a mutation from a gene string `start` to a gene string `end` where one mutation is defined as one single character changed in the gene string. +Suppose we need to investigate a mutation from a gene string `startGene` to a gene string `endGene` where one mutation is defined as one single character changed in the gene string. * For example, `"AACCGGTT" --> "AACCGGTA"` is one mutation. There is also a gene bank `bank` that records all the valid gene mutations. A gene must be in `bank` to make it a valid gene string. -Given the two gene strings `start` and `end` and the gene bank `bank`, return _the minimum number of mutations needed to mutate from_ `start` _to_ `end`. If there is no such a mutation, return `-1`. +Given the two gene strings `startGene` and `endGene` and the gene bank `bank`, return _the minimum number of mutations needed to mutate from_ `startGene` _to_ `endGene`. If there is no such a mutation, return `-1`. Note that the starting point is assumed to be valid, so it might not be included in the bank. **Example 1:** -**Input:** start = "AACCGGTT", end = "AACCGGTA", bank = ["AACCGGTA"] +**Input:** startGene = "AACCGGTT", endGene = "AACCGGTA", bank = ["AACCGGTA"] **Output:** 1 **Example 2:** -**Input:** start = "AACCGGTT", end = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"] +**Input:** startGene = "AACCGGTT", endGene = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"] **Output:** 2 -**Example 3:** - -**Input:** start = "AAAAACCC", end = "AACCCCCC", bank = ["AAAACCCC","AAACCCCC","AACCCCCC"] - -**Output:** 3 - **Constraints:** -* `start.length == 8` -* `end.length == 8` * `0 <= bank.length <= 10` -* `bank[i].length == 8` -* `start`, `end`, and `bank[i]` consist of only the characters `['A', 'C', 'G', 'T']`. \ No newline at end of file +* `startGene.length == endGene.length == bank[i].length == 8` +* `startGene`, `endGene`, and `bank[i]` consist of only the characters `['A', 'C', 'G', 'T']`. \ No newline at end of file diff --git a/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md b/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md index f3bc0a87e..2e062e94b 100644 --- a/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md +++ b/src/main/java/g0401_0500/s0438_find_all_anagrams_in_a_string/readme.md @@ -2,9 +2,7 @@ Medium -Given two strings `s` and `p`, return _an array of all the start indices of_ `p`_'s anagrams in_ `s`. You may return the answer in **any order**. - -An **Anagram** is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. +Given two strings `s` and `p`, return an array of all the start indices of `p`'s anagrams in `s`. You may return the answer in **any order**. **Example 1:** @@ -32,4 +30,4 @@ An **Anagram** is a word or phrase formed by rearranging the letters of a differ **Constraints:** * 1 <= s.length, p.length <= 3 * 104 -* `s` and `p` consist of lowercase English letters. +* `s` and `p` consist of lowercase English letters. \ No newline at end of file diff --git a/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md b/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md index 4b437072e..ad4c2952b 100644 --- a/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md +++ b/src/main/java/g0501_0600/s0560_subarray_sum_equals_k/readme.md @@ -2,7 +2,9 @@ Medium -Given an array of integers `nums` and an integer `k`, return _the total number of continuous subarrays whose sum equals to `k`_. +Given an array of integers `nums` and an integer `k`, return _the total number of subarrays whose sum equals to_ `k`. + +A subarray is a contiguous **non-empty** sequence of elements within an array. **Example 1:** diff --git a/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md b/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md index 8bae0a477..1099bb2bd 100644 --- a/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md +++ b/src/main/java/g0601_0700/s0637_average_of_levels_in_binary_tree/readme.md @@ -10,7 +10,7 @@ Given the `root` of a binary tree, return _the average value of the nodes on eac **Input:** root = [3,9,20,null,null,15,7] -**Output:** [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11]. +**Output:** [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11]. **Example 2:** @@ -18,7 +18,7 @@ Given the `root` of a binary tree, return _the average value of the nodes on eac **Input:** root = [3,9,20,15,7] -**Output:** [3.00000,14.50000,11.00000] +**Output:** [3.00000,14.50000,11.00000] **Constraints:** diff --git a/src/main/java/g0701_0800/s0763_partition_labels/readme.md b/src/main/java/g0701_0800/s0763_partition_labels/readme.md index 143aa81a6..1b3a56057 100644 --- a/src/main/java/g0701_0800/s0763_partition_labels/readme.md +++ b/src/main/java/g0701_0800/s0763_partition_labels/readme.md @@ -2,7 +2,9 @@ Medium -You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part. +You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example, the string `"ababcc"` can be partitioned into `["abab", "cc"]`, but partitions such as `["aba", "bcc"]` or `["ab", "ab", "cc"]` are invalid. + +Note that the partition is done so that after concatenating all the parts in order, the resultant string should be `s`. Return _a list of integers representing the size of these parts_. @@ -12,11 +14,7 @@ Return _a list of integers representing the size of these parts_. **Output:** [9,7,8] -**Explanation:** - - The partition is "ababcbaca", "defegde", "hijhklij". - This is a partition so that each letter appears in at most one part. - A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts. +**Explanation:** The partition is "ababcbaca", "defegde", "hijhklij". This is a partition so that each letter appears in at most one part. A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts. **Example 2:** diff --git a/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md b/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md index f143794a6..1f64f55ae 100644 --- a/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md +++ b/src/main/java/g0901_1000/s0909_snakes_and_ladders/readme.md @@ -11,13 +11,13 @@ You start on square `1` of the board. In each move, starting from square `curr`, * If `next` has a snake or ladder, you **must** move to the destination of that snake or ladder. Otherwise, you move to `next`. * The game ends when you reach the square n2. -A board square on row `r` and column `c` has a snake or ladder if `board[r][c] != -1`. The destination of that snake or ladder is `board[r][c]`. Squares `1` and n2 do not have a snake or ladder. +A board square on row `r` and column `c` has a snake or ladder if `board[r][c] != -1`. The destination of that snake or ladder is `board[r][c]`. Squares `1` and n2 are not the starting points of any snake or ladder. -Note that you only take a snake or ladder at most once per move. If the destination to a snake or ladder is the start of another snake or ladder, you do **not** follow the subsequent snake or ladder. +Note that you only take a snake or ladder at most once per dice roll. If the destination to a snake or ladder is the start of another snake or ladder, you do **not** follow the subsequent snake or ladder. * For example, suppose the board is `[[-1,4],[-1,3]]`, and on the first move, your destination square is `2`. You follow the ladder to square `3`, but do **not** follow the subsequent ladder to `4`. -Return _the least number of moves required to reach the square_ n2_. If it is not possible to reach the square, return_ `-1`. +Return _the least number of dice rolls required to reach the square_ n2_. If it is not possible to reach the square, return_ `-1`. **Example 1:** @@ -45,11 +45,11 @@ This is the lowest possible number of moves to reach the last square, so return **Input:** board = [[-1,-1],[-1,3]] -**Output:** 1 +**Output:** 1 **Constraints:** * `n == board.length == board[i].length` * `2 <= n <= 20` -* `grid[i][j]` is either `-1` or in the range [1, n2]. -* The squares labeled `1` and n2 do not have any ladders or snakes. \ No newline at end of file +* `board[i][j]` is either `-1` or in the range [1, n2]. +* The squares labeled `1` and n2 are not the starting points of any snake or ladder. \ No newline at end of file