From 96d2da8dd1e6db19505c3200872249c3edb90ad1 Mon Sep 17 00:00:00 2001 From: ThanhNIT Date: Sun, 2 Nov 2025 21:13:15 +0700 Subject: [PATCH 1/2] Update readme for tasks 134-169 --- .../java/g0101_0200/s0134_gas_station/readme.md | 8 ++++---- .../java/g0101_0200/s0136_single_number/readme.md | 6 +++--- .../s0138_copy_list_with_random_pointer/readme.md | 10 +--------- .../readme.md | 13 +++++++++---- .../s0151_reverse_words_in_a_string/readme.md | 12 ------------ .../s0152_maximum_product_subarray/readme.md | 8 ++++---- .../readme.md | 2 +- src/main/java/g0101_0200/s0155_min_stack/readme.md | 9 ++++----- .../readme.md | 6 +++--- .../g0101_0200/s0162_find_peak_element/readme.md | 4 ++-- .../readme.md | 10 ++++++---- .../g0101_0200/s0169_majority_element/readme.md | 2 +- 12 files changed, 38 insertions(+), 52 deletions(-) diff --git a/src/main/java/g0101_0200/s0134_gas_station/readme.md b/src/main/java/g0101_0200/s0134_gas_station/readme.md index 18c57df57..fd0955e42 100644 --- a/src/main/java/g0101_0200/s0134_gas_station/readme.md +++ b/src/main/java/g0101_0200/s0134_gas_station/readme.md @@ -6,7 +6,7 @@ There are `n` gas stations along a circular route, where the amount of gas at th You have a car with an unlimited gas tank and it costs `cost[i]` of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations. -Given two integer arrays `gas` and `cost`, return _the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return_ `-1`. If there exists a solution, it is **guaranteed** to be **unique** +Given two integer arrays `gas` and `cost`, return _the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return_ `-1`. If there exists a solution, it is **guaranteed** to be **unique**. **Example 1:** @@ -41,7 +41,7 @@ Given two integer arrays `gas` and `cost`, return _the starting gas station's in **Constraints:** -* `gas.length == n` -* `cost.length == n` +* `n == gas.length == cost.length` * 1 <= n <= 105 -* 0 <= gas[i], cost[i] <= 104 \ No newline at end of file +* 0 <= gas[i], cost[i] <= 104 +* The input is generated such that the answer is unique. \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0136_single_number/readme.md b/src/main/java/g0101_0200/s0136_single_number/readme.md index c8d377bc7..5246177bb 100644 --- a/src/main/java/g0101_0200/s0136_single_number/readme.md +++ b/src/main/java/g0101_0200/s0136_single_number/readme.md @@ -10,19 +10,19 @@ You must implement a solution with a linear runtime complexity and use only cons **Input:** nums = [2,2,1] -**Output:** 1 +**Output:** 1 **Example 2:** **Input:** nums = [4,1,2,1,2] -**Output:** 4 +**Output:** 4 **Example 3:** **Input:** nums = [1] -**Output:** 1 +**Output:** 1 **Constraints:** diff --git a/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md b/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md index 4a2316baa..031f4e738 100644 --- a/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md +++ b/src/main/java/g0101_0200/s0138_copy_list_with_random_pointer/readme.md @@ -41,18 +41,10 @@ Your code will **only** be given the `head` of the original linked list. **Output:** [[3,null],[3,0],[3,null]] -**Example 4:** - -**Input:** head = [] - -**Output:** [] - -**Explanation:** The given linked list is empty (null pointer), so return null. - **Constraints:** * `0 <= n <= 1000` -* `-10000 <= Node.val <= 10000` +* -104 <= Node.val <= 104 * `Node.random` is `null` or is pointing to some node in the linked list. To solve the "Copy List with Random Pointer" problem in Java with a `Solution` class, we'll use a HashMap to maintain a mapping between the original nodes and their corresponding copied nodes. Below are the steps: diff --git a/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md b/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md index a16fe93e2..07842fae1 100644 --- a/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md +++ b/src/main/java/g0101_0200/s0150_evaluate_reverse_polish_notation/readme.md @@ -2,13 +2,18 @@ Medium -Evaluate the value of an arithmetic expression in [Reverse Polish Notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation). +You are given an array of strings `tokens` that represents an arithmetic expression in a [Reverse Polish Notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation). -Valid operators are `+`, `-`, `*`, and `/`. Each operand may be an integer or another expression. +Evaluate the expression. Return _an integer that represents the value of the expression_. -**Note** that division between two integers should truncate toward zero. +**Note** that: -It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation. +* The valid operators are `'+'`, `'-'`, `'*'`, and `'/'`. +* Each operand may be an integer or another expression. +* The division between two integers always **truncates toward zero**. +* There will not be any division by zero. +* The input represents a valid arithmetic expression in a reverse polish notation. +* The answer and all the intermediate calculations can be represented in a **32-bit** integer. **Example 1:** diff --git a/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md b/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md index 8817deca4..22a72116e 100644 --- a/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md +++ b/src/main/java/g0101_0200/s0151_reverse_words_in_a_string/readme.md @@ -32,18 +32,6 @@ Return _a string of the words in reverse order concatenated by a single space._ **Explanation:** You need to reduce multiple spaces between two words to a single space in the reversed string. -**Example 4:** - -**Input:** s = " Bob Loves Alice " - -**Output:** "Alice Loves Bob" - -**Example 5:** - -**Input:** s = "Alice does not even like bob" - -**Output:** "bob like even not does Alice" - **Constraints:** * 1 <= s.length <= 104 diff --git a/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md b/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md index 13f4e9510..eb71aaece 100644 --- a/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md +++ b/src/main/java/g0101_0200/s0152_maximum_product_subarray/readme.md @@ -2,11 +2,11 @@ Medium -Given an integer array `nums`, find a contiguous non-empty subarray within the array that has the largest product, and return _the product_. +Given an integer array `nums`, find a **non-empty subarrays** that has the largest product, and return _the product_. -It is **guaranteed** that the answer will fit in a **32-bit** integer. +The test cases are generated so that the answer will fit in a **32-bit** integer. -A **subarray** is a contiguous subsequence of the array. +**Note** that the product of an array with a single element is the value of that element. **Example 1:** @@ -28,4 +28,4 @@ A **subarray** is a contiguous subsequence of the array. * 1 <= nums.length <= 2 * 104 * `-10 <= nums[i] <= 10` -* The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer. \ No newline at end of file +* The product of any subarray of `nums` is **guaranteed** to fit in a **32-bit** integer. \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md b/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md index db0231d64..d343dafdf 100644 --- a/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md +++ b/src/main/java/g0101_0200/s0153_find_minimum_in_rotated_sorted_array/readme.md @@ -11,7 +11,7 @@ Notice that **rotating** an array `[a[0], a[1], a[2], ..., a[n-1]]` 1 time resul Given the sorted rotated array `nums` of **unique** elements, return _the minimum element of this array_. -You must write an algorithm that runs in `O(log n) time.` +You must write an algorithm that runs in `O(log n) time`. **Example 1:** diff --git a/src/main/java/g0101_0200/s0155_min_stack/readme.md b/src/main/java/g0101_0200/s0155_min_stack/readme.md index f3a3af2aa..b170fcca6 100644 --- a/src/main/java/g0101_0200/s0155_min_stack/readme.md +++ b/src/main/java/g0101_0200/s0155_min_stack/readme.md @@ -1,6 +1,6 @@ 155\. Min Stack -Easy +Medium Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. @@ -12,12 +12,11 @@ Implement the `MinStack` class: * `int top()` gets the top element of the stack. * `int getMin()` retrieves the minimum element in the stack. -**Example 1:** +You must implement a solution with `O(1)` time complexity for each function. -**Input** +**Example 1:** - ["MinStack","push","push","push","getMin","pop","top","getMin"] - [[],[-2],[0],[-3],[],[],[],[]] +**Input** ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]] **Output:** [null,null,null,null,-3,null,0,-2] diff --git a/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md index de0e1d801..39d7ac6b4 100644 --- a/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md +++ b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md @@ -32,7 +32,7 @@ The judge will then create the linked structure based on these inputs and pass t **Output:** Intersected at '8' -**Explanation:** The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. +**Explanation:** The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. - Note that the intersected node's value is not 1 because the nodes with value 1 in A and B (2nd node in A and 3rd node in B) are different node references. In other words, they point to two different locations in memory, while the nodes with value 8 in A and B (3rd node in A and 4th node in B) point to the same location in memory. **Example 2:** @@ -58,11 +58,11 @@ The judge will then create the linked structure based on these inputs and pass t * The number of nodes of `listA` is in the `m`. * The number of nodes of `listB` is in the `n`. -* 0 <= m, n <= 3 * 104 +* 1 <= m, n <= 3 * 104 * 1 <= Node.val <= 105 * `0 <= skipA <= m` * `0 <= skipB <= n` * `intersectVal` is `0` if `listA` and `listB` do not intersect. * `intersectVal == listA[skipA] == listB[skipB]` if `listA` and `listB` intersect. -**Follow up:** Could you write a solution that runs in `O(n)` time and use only `O(1)` memory? \ No newline at end of file +**Follow up:** Could you write a solution that runs in `O(m + n)` time and use only `O(1)` memory? \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0162_find_peak_element/readme.md b/src/main/java/g0101_0200/s0162_find_peak_element/readme.md index 06b668448..fd90613ae 100644 --- a/src/main/java/g0101_0200/s0162_find_peak_element/readme.md +++ b/src/main/java/g0101_0200/s0162_find_peak_element/readme.md @@ -4,9 +4,9 @@ Medium A peak element is an element that is strictly greater than its neighbors. -Given an integer array `nums`, find a peak element, and return its index. If the array contains multiple peaks, return the index to **any of the peaks**. +Given a **0-indexed** integer array `nums`, find a peak element, and return its index. If the array contains multiple peaks, return the index to **any of the peaks**. -You may imagine that `nums[-1] = nums[n] = -∞`. +You may imagine that `nums[-1] = nums[n] = -∞`. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array. You must write an algorithm that runs in `O(log n)` time. diff --git a/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md b/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md index 81d951f60..712971aa0 100644 --- a/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md +++ b/src/main/java/g0101_0200/s0167_two_sum_ii_input_array_is_sorted/readme.md @@ -1,6 +1,6 @@ 167\. Two Sum II - Input Array Is Sorted -Easy +Medium Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. @@ -8,9 +8,11 @@ Return _the indices of the two numbers,_ index1 _and_ 2,7,11,15], target = 9 **Output:** [1,2] @@ -18,7 +20,7 @@ The tests are generated such that there is **exactly one solution**. You **may n **Example 2:** -**Input:** numbers = [2,3,4], target = 6 +**Input:** numbers = [2,3,4], target = 6 **Output:** [1,3] @@ -26,7 +28,7 @@ The tests are generated such that there is **exactly one solution**. You **may n **Example 3:** -**Input:** numbers = [\-1,0], target = -1 +**Input:** numbers = [\-1,0], target = -1 **Output:** [1,2] diff --git a/src/main/java/g0101_0200/s0169_majority_element/readme.md b/src/main/java/g0101_0200/s0169_majority_element/readme.md index 5ea5071e8..b4c103567 100644 --- a/src/main/java/g0101_0200/s0169_majority_element/readme.md +++ b/src/main/java/g0101_0200/s0169_majority_element/readme.md @@ -22,6 +22,6 @@ The majority element is the element that appears more than `⌊n / 2⌋` times. * `n == nums.length` * 1 <= n <= 5 * 104 -* -231 <= nums[i] <= 231 - 1 +* -109 <= nums[i] <= 109 **Follow-up:** Could you solve the problem in linear time and in `O(1)` space? \ No newline at end of file From 759c0a329767981d25b3831f504661805d2b051d Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Sun, 2 Nov 2025 16:28:47 +0200 Subject: [PATCH 2/2] Update readme.md --- .../s0160_intersection_of_two_linked_lists/readme.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md index 39d7ac6b4..a1a20f2ea 100644 --- a/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md +++ b/src/main/java/g0101_0200/s0160_intersection_of_two_linked_lists/readme.md @@ -32,7 +32,11 @@ The judge will then create the linked structure based on these inputs and pass t **Output:** Intersected at '8' -**Explanation:** The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. - Note that the intersected node's value is not 1 because the nodes with value 1 in A and B (2nd node in A and 3rd node in B) are different node references. In other words, they point to two different locations in memory, while the nodes with value 8 in A and B (3rd node in A and 4th node in B) point to the same location in memory. +**Explanation:** The intersected node's value is 8 (note that this must not be 0 if the two lists intersect). + +From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B. + +- Note that the intersected node's value is not 1 because the nodes with value 1 in A and B (2nd node in A and 3rd node in B) are different node references. In other words, they point to two different locations in memory, while the nodes with value 8 in A and B (3rd node in A and 4th node in B) point to the same location in memory. **Example 2:** @@ -65,4 +69,4 @@ The judge will then create the linked structure based on these inputs and pass t * `intersectVal` is `0` if `listA` and `listB` do not intersect. * `intersectVal == listA[skipA] == listB[skipB]` if `listA` and `listB` intersect. -**Follow up:** Could you write a solution that runs in `O(m + n)` time and use only `O(1)` memory? \ No newline at end of file +**Follow up:** Could you write a solution that runs in `O(m + n)` time and use only `O(1)` memory?