From 5ecb3ad347a9e9da76bba53de09be849ba3e6695 Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Sun, 2 Nov 2025 21:31:28 +0700 Subject: [PATCH] Update readme for tasks 172-215 --- .../readme.md | 6 +-- .../g0101_0200/s0189_rotate_array/readme.md | 2 +- .../g0101_0200/s0190_reverse_bits/readme.md | 44 ++++++++++++++----- .../s0191_number_of_1_bits/readme.md | 29 ++++++------ .../readme.md | 24 +++++++--- .../s0205_isomorphic_strings/readme.md | 17 +++++-- .../s0207_course_schedule/readme.md | 2 +- .../s0209_minimum_size_subarray_sum/readme.md | 4 +- .../s0210_course_schedule_ii/readme.md | 10 +---- .../readme.md | 9 ++-- .../readme.md | 4 +- 11 files changed, 96 insertions(+), 55 deletions(-) diff --git a/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md b/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md index db592c56c..092d32c77 100644 --- a/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md +++ b/src/main/java/g0101_0200/s0188_best_time_to_buy_and_sell_stock_iv/readme.md @@ -4,7 +4,7 @@ Hard You are given an integer array `prices` where `prices[i]` is the price of a given stock on the ith day, and an integer `k`. -Find the maximum profit you can achieve. You may complete at most `k` transactions. +Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). @@ -26,6 +26,6 @@ Find the maximum profit you can achieve. You may complete at most `k` transactio **Constraints:** -* `0 <= k <= 100` -* `0 <= prices.length <= 1000` +* `1 <= k <= 100` +* `1 <= prices.length <= 1000` * `0 <= prices[i] <= 1000` \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0189_rotate_array/readme.md b/src/main/java/g0101_0200/s0189_rotate_array/readme.md index 390f2692e..7b85b1dcd 100644 --- a/src/main/java/g0101_0200/s0189_rotate_array/readme.md +++ b/src/main/java/g0101_0200/s0189_rotate_array/readme.md @@ -2,7 +2,7 @@ Medium -Given an array, rotate the array to the right by `k` steps, where `k` is non-negative. +Given an integer array `nums`, rotate the array to the right by `k` steps, where `k` is non-negative. **Example 1:** diff --git a/src/main/java/g0101_0200/s0190_reverse_bits/readme.md b/src/main/java/g0101_0200/s0190_reverse_bits/readme.md index cd57e6556..ebe579022 100644 --- a/src/main/java/g0101_0200/s0190_reverse_bits/readme.md +++ b/src/main/java/g0101_0200/s0190_reverse_bits/readme.md @@ -2,31 +2,51 @@ Easy -Reverse bits of a given 32 bits unsigned integer. +Reverse bits of a given 32 bits signed integer. -**Note:** +**Example 1:** -* Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned. -* In Java, the compiler represents the signed integers using [2's complement notation](https://en.wikipedia.org/wiki/Two%27s_complement). Therefore, in **Example 2** above, the input represents the signed integer `-3` and the output represents the signed integer `-1073741825`. +**Input:** n = 43261596 -**Example 1:** +**Output:** 964176192 + +**Explanation:** + +Integer + +Binary + +43261596 -**Input:** n = 00000010100101000001111010011100 +00000010100101000001111010011100 -**Output:** 964176192 (00111001011110000010100101000000) +964176192 -**Explanation:** The input binary string **00000010100101000001111010011100** represents the unsigned integer 43261596, so return 964176192 which its binary representation is **00111001011110000010100101000000**. +00111001011110000010100101000000 **Example 2:** -**Input:** n = 11111111111111111111111111111101 +**Input:** n = 2147483644 + +**Output:** 1073741822 + +**Explanation:** + +Integer + +Binary + +2147483644 + +01111111111111111111111111111100 -**Output:** 3221225471 (10111111111111111111111111111111) +1073741822 -**Explanation:** The input binary string **11111111111111111111111111111101** represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is **10111111111111111111111111111111**. +00111111111111111111111111111110 **Constraints:** -* The input must be a **binary string** of length `32` +* 0 <= n <= 231 - 2 +* `n` is even. **Follow up:** If this function is called many times, how would you optimize it? \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md b/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md index 2237b5c87..7db6444f3 100644 --- a/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md +++ b/src/main/java/g0101_0200/s0191_number_of_1_bits/readme.md @@ -2,39 +2,40 @@ Easy -Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the [Hamming weight](http://en.wikipedia.org/wiki/Hamming_weight)). - -**Note:** - -* Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned. -* In Java, the compiler represents the signed integers using [2's complement notation](https://en.wikipedia.org/wiki/Two%27s_complement). Therefore, in **Example 3**, the input represents the signed integer. `-3`. +Given a positive integer `n`, write a function that returns the number of set bits in its binary representation (also known as the [Hamming weight](http://en.wikipedia.org/wiki/Hamming_weight)). **Example 1:** -**Input:** n = 00000000000000000000000000001011 +**Input:** n = 11 **Output:** 3 -**Explanation:** The input binary string **00000000000000000000000000001011** has a total of three '1' bits. +**Explanation:** + +The input binary string **1011** has a total of three set bits. **Example 2:** -**Input:** n = 00000000000000000000000010000000 +**Input:** n = 128 **Output:** 1 -**Explanation:** The input binary string **00000000000000000000000010000000** has a total of one '1' bit. +**Explanation:** + +The input binary string **10000000** has a total of one set bit. **Example 3:** -**Input:** n = 11111111111111111111111111111101 +**Input:** n = 2147483645 + +**Output:** 30 -**Output:** 31 +**Explanation:** -**Explanation:** The input binary string **11111111111111111111111111111101** has a total of thirty one '1' bits. +The input binary string **1111111111111111111111111111101** has a total of thirty set bits. **Constraints:** -* The input must be a **binary string** of length `32`. +* 1 <= n <= 231 - 1 **Follow up:** If this function is called many times, how would you optimize it? \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md b/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md index cce1fc176..e2b9590ab 100644 --- a/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md +++ b/src/main/java/g0101_0200/s0199_binary_tree_right_side_view/readme.md @@ -6,23 +6,35 @@ Given the `root` of a binary tree, imagine yourself standing on the **right side **Example 1:** -![](https://assets.leetcode.com/uploads/2021/02/14/tree.jpg) - **Input:** root = [1,2,3,null,5,null,4] -**Output:** [1,3,4] +**Output:** [1,3,4] + +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/11/24/tmpd5jn43fs-1.png) **Example 2:** -**Input:** root = [1,null,3] +**Input:** root = [1,2,3,4,null,null,null,5] + +**Output:** [1,3,4,5] -**Output:** [1,3] +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/11/24/tmpkpe40xeh-1.png) **Example 3:** +**Input:** root = [1,null,3] + +**Output:** [1,3] + +**Example 4:** + **Input:** root = [] -**Output:** [] +**Output:** [] **Constraints:** diff --git a/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md b/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md index 24fe5c526..d57bc1250 100644 --- a/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md +++ b/src/main/java/g0201_0300/s0205_isomorphic_strings/readme.md @@ -12,19 +12,30 @@ All occurrences of a character must be replaced with another character while pre **Input:** s = "egg", t = "add" -**Output:** true +**Output:** true + +**Explanation:** + +The strings `s` and `t` can be made identical by: + +* Mapping `'e'` to `'a'`. +* Mapping `'g'` to `'d'`. **Example 2:** **Input:** s = "foo", t = "bar" -**Output:** false +**Output:** false + +**Explanation:** + +The strings `s` and `t` can not be made identical as `'o'` needs to be mapped to both `'a'` and `'r'`. **Example 3:** **Input:** s = "paper", t = "title" -**Output:** true +**Output:** true **Constraints:** diff --git a/src/main/java/g0201_0300/s0207_course_schedule/readme.md b/src/main/java/g0201_0300/s0207_course_schedule/readme.md index a7b1e9c70..2be17e8f0 100644 --- a/src/main/java/g0201_0300/s0207_course_schedule/readme.md +++ b/src/main/java/g0201_0300/s0207_course_schedule/readme.md @@ -26,7 +26,7 @@ Return `true` if you can finish all courses. Otherwise, return `false`. **Constraints:** -* 1 <= numCourses <= 105 +* `1 <= numCourses <= 2000` * `0 <= prerequisites.length <= 5000` * `prerequisites[i].length == 2` * 0 <= ai, bi < numCourses diff --git a/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md b/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md index bc5d1b070..15f80a0b2 100644 --- a/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md +++ b/src/main/java/g0201_0300/s0209_minimum_size_subarray_sum/readme.md @@ -2,7 +2,7 @@ Medium -Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a **contiguous subarray** [numsl, numsl+1, ..., numsr-1, numsr] of which the sum is greater than or equal to `target`. If there is no such subarray, return `0` instead. +Given an array of positive integers `nums` and a positive integer `target`, return _the **minimal length** of a_ **non-empty subarrays** _whose sum is greater than or equal to_ `target`. If there is no such subarray, return `0` instead. **Example 1:** @@ -28,6 +28,6 @@ Given an array of positive integers `nums` and a positive integer `target`, retu * 1 <= target <= 109 * 1 <= nums.length <= 105 -* 1 <= nums[i] <= 105 +* 1 <= nums[i] <= 104 **Follow up:** If you have figured out the `O(n)` solution, try coding another solution of which the time complexity is `O(n log(n))`. \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md b/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md index 5b8dc5ee6..32ef6b760 100644 --- a/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md +++ b/src/main/java/g0201_0300/s0210_course_schedule_ii/readme.md @@ -14,10 +14,7 @@ Return _the ordering of courses you should take to finish all courses_. If there **Output:** [0,1] -**Explanation:** - - There are a total of 2 courses to take. To take course 1 you should have finished course 0. - So the correct course order is [0,1]. +**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0. So the correct course order is [0,1]. **Example 2:** @@ -25,10 +22,7 @@ Return _the ordering of courses you should take to finish all courses_. If there **Output:** [0,2,1,3] -**Explanation:** - - There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0. - So one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3]. +**Explanation:** There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0. So one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3]. **Example 3:** diff --git a/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md b/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md index 940cb2f1a..d16d16268 100644 --- a/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md +++ b/src/main/java/g0201_0300/s0211_design_add_and_search_words_data_structure/readme.md @@ -33,7 +33,8 @@ Implement the `WordDictionary` class: **Constraints:** -* `1 <= word.length <= 500` -* `word` in `addWord` consists lower-case English letters. -* `word` in `search` consist of `'.'` or lower-case English letters. -* At most `50000` calls will be made to `addWord` and `search`. +* `1 <= word.length <= 25` +* `word` in `addWord` consists of lowercase English letters. +* `word` in `search` consist of `'.'` or lowercase English letters. +* There will be at most `2` dots in `word` for `search` queries. +* At most 104 calls will be made to `addWord` and `search`. \ No newline at end of file diff --git a/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md b/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md index c4c64cba0..aa5b5682a 100644 --- a/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md +++ b/src/main/java/g0201_0300/s0215_kth_largest_element_in_an_array/readme.md @@ -6,6 +6,8 @@ Given an integer array `nums` and an integer `k`, return _the_ kthkth largest element in the sorted order, not the kth distinct element. +Can you solve it without sorting? + **Example 1:** **Input:** nums = [3,2,1,5,6,4], k = 2 @@ -20,5 +22,5 @@ Note that it is the kth largest element in the sorted or **Constraints:** -* 1 <= k <= nums.length <= 104 +* 1 <= k <= nums.length <= 105 * -104 <= nums[i] <= 104 \ No newline at end of file