Skip to content

Commit 7876108

Browse files
authored
Updated tasks 50-72
1 parent bd92171 commit 7876108

File tree

13 files changed

+90
-92
lines changed

13 files changed

+90
-92
lines changed

src/main/java/g0001_0100/s0050_powx_n/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ Implement [pow(x, n)](http://www.cplusplus.com/reference/valarray/pow/), which c
2828

2929
* `-100.0 < x < 100.0`
3030
* <code>-2<sup>31</sup> <= n <= 2<sup>31</sup>-1</code>
31+
* `n` is an integer.
32+
* Either `x` is not zero or `n > 0`.
3133
* <code>-10<sup>4</sup> <= x<sup>n</sup> <= 10<sup>4</sup></code>

src/main/java/g0001_0100/s0053_maximum_subarray/readme.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
53\. Maximum Subarray
22

3-
Easy
3+
Medium
44

5-
Given an integer array `nums`, find the contiguous subarray (containing at least one number) which has the largest sum and return _its sum_.
6-
7-
A **subarray** is a **contiguous** part of an array.
5+
Given an integer array `nums`, find the **non-empty subarrays** with the largest sum, and return _its sum_.
86

97
**Example 1:**
108

119
**Input:** nums = [-2,1,-3,4,-1,2,1,-5,4]
1210

1311
**Output:** 6
1412

15-
**Explanation:** [4,-1,2,1] has the largest sum = 6.
13+
**Explanation:** The subarray [4,-1,2,1] has the largest sum 6.
1614

1715
**Example 2:**
1816

1917
**Input:** nums = [1]
2018

21-
**Output:** 1
19+
**Output:** 1
20+
21+
**Explanation:** The subarray [1] has the largest sum 1.
2222

2323
**Example 3:**
2424

2525
**Input:** nums = [5,4,-1,7,8]
2626

27-
**Output:** 23
27+
**Output:** 23
28+
29+
**Explanation:** The subarray [5,4,-1,7,8] has the largest sum 23.
2830

2931
**Constraints:**
3032

src/main/java/g0001_0100/s0056_merge_intervals/readme.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Given an array of `intervals` where <code>intervals[i] = [start<sub>i</sub>, end
1010

1111
**Output:** [[1,6],[8,10],[15,18]]
1212

13-
**Explanation:** Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
13+
**Explanation:** Since intervals [1,3] and [2,6] overlap, merge them into [1,6].
1414

1515
**Example 2:**
1616

@@ -20,6 +20,14 @@ Given an array of `intervals` where <code>intervals[i] = [start<sub>i</sub>, end
2020

2121
**Explanation:** Intervals [1,4] and [4,5] are considered overlapping.
2222

23+
**Example 3:**
24+
25+
**Input:** intervals = [[4,7],[1,4]]
26+
27+
**Output:** [[1,7]]
28+
29+
**Explanation:** Intervals [1,4] and [4,7] are considered overlapping.
30+
2331
**Constraints:**
2432

2533
* <code>1 <= intervals.length <= 10<sup>4</sup></code>
@@ -57,4 +65,4 @@ class Solution {
5765
}
5866
```
5967

60-
This implementation efficiently merges overlapping intervals in the given array `intervals` using sorting and iteration, with a time complexity of O(n log n) due to sorting.
68+
This implementation efficiently merges overlapping intervals in the given array `intervals` using sorting and iteration, with a time complexity of O(n log n) due to sorting.

src/main/java/g0001_0100/s0057_insert_interval/readme.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Insert `newInterval` into `intervals` such that `intervals` is still sorted in a
88

99
Return `intervals` _after the insertion_.
1010

11+
**Note** that you don't need to modify `intervals` in-place. You can make a new array and return it.
12+
1113
**Example 1:**
1214

1315
**Input:** intervals = [[1,3],[6,9]], newInterval = [2,5]
@@ -20,25 +22,7 @@ Return `intervals` _after the insertion_.
2022

2123
**Output:** [[1,2],[3,10],[12,16]]
2224

23-
**Explanation:** Because the new interval `[4,8]` overlaps with `[3,5],[6,7],[8,10]`.
24-
25-
**Example 3:**
26-
27-
**Input:** intervals = [], newInterval = [5,7]
28-
29-
**Output:** [[5,7]]
30-
31-
**Example 4:**
32-
33-
**Input:** intervals = [[1,5]], newInterval = [2,3]
34-
35-
**Output:** [[1,5]]
36-
37-
**Example 5:**
38-
39-
**Input:** intervals = [[1,5]], newInterval = [2,7]
40-
41-
**Output:** [[1,7]]
25+
**Explanation:** Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
4226

4327
**Constraints:**
4428

src/main/java/g0001_0100/s0058_length_of_last_word/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Easy
44

5-
Given a string `s` consisting of some words separated by some number of spaces, return _the length of the **last** word in the string._
5+
Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
66

7-
A **word** is a maximal substring consisting of non-space characters only.
7+
A **word** is a maximal **substring** consisting of non-space characters only.
88

99
**Example 1:**
1010

src/main/java/g0001_0100/s0062_unique_paths/readme.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Medium
44

5-
A robot is located at the top-left corner of a `m x n` grid (marked 'Start' in the diagram below).
5+
There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
66

7-
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
7+
Given the two integers `m` and `n`, return _the number of possible unique paths that the robot can take to reach the bottom-right corner_.
88

9-
How many possible unique paths are there?
9+
The test cases are generated so that the answer will be less than or equal to <code>2 * 10<sup>9</sup></code>.
1010

1111
**Example 1:**
1212

@@ -22,24 +22,7 @@ How many possible unique paths are there?
2222

2323
**Output:** 3
2424

25-
**Explanation:**
26-
27-
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
28-
1. Right -> Down -> Down
29-
2. Down -> Down -> Right
30-
3. Down -> Right -> Down
31-
32-
**Example 3:**
33-
34-
**Input:** m = 7, n = 3
35-
36-
**Output:** 28
37-
38-
**Example 4:**
39-
40-
**Input:** m = 3, n = 3
41-
42-
**Output:** 6
25+
**Explanation:** From the top-left corner, there are a total of 3 ways to reach the bottom-right corner: 1. Right -> Down -> Down 2. Down -> Down -> Right 3. Down -> Right -> Down
4326

4427
**Constraints:**
4528

src/main/java/g0001_0100/s0063_unique_paths_ii/readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Medium
44

5-
A robot is located at the top-left corner of a `m x n` grid (marked 'Start' in the diagram below).
5+
You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
66

7-
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
7+
An obstacle and space are marked as `1` or `0` respectively in `grid`. A path that the robot takes cannot include **any** square that is an obstacle.
88

9-
Now consider if some obstacles are added to the grids. How many unique paths would there be?
9+
Return _the number of possible unique paths that the robot can take to reach the bottom-right corner_.
1010

11-
An obstacle and space is marked as `1` and `0` respectively in the grid.
11+
The testcases are generated so that the answer will be less than or equal to <code>2 * 10<sup>9</sup></code>.
1212

1313
**Example 1:**
1414

src/main/java/g0001_0100/s0064_minimum_path_sum/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Given a `m x n` `grid` filled with non-negative numbers, find a path from top le
2727
* `m == grid.length`
2828
* `n == grid[i].length`
2929
* `1 <= m, n <= 200`
30-
* `0 <= grid[i][j] <= 100`
30+
* `0 <= grid[i][j] <= 200`
3131

3232
To solve the "Minimum Path Sum" problem in Java with the Solution class, follow these steps:
3333

src/main/java/g0001_0100/s0066_plus_one/readme.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Easy
44

5-
You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
5+
You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the <code>i<sup>th</sup></code> digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
66

77
Increment the large integer by one and return _the resulting array of digits_.
88

@@ -24,14 +24,6 @@ Increment the large integer by one and return _the resulting array of digits_.
2424

2525
**Example 3:**
2626

27-
**Input:** digits = [0]
28-
29-
**Output:** [1]
30-
31-
**Explanation:** The array represents the integer 0. Incrementing by one gives 0 + 1 = 1. Thus, the result should be [1].
32-
33-
**Example 4:**
34-
3527
**Input:** digits = [9]
3628

3729
**Output:** [1,0]

src/main/java/g0001_0100/s0068_text_justification/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ You should pack your words in a greedy approach; that is, pack as many words as
88

99
Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.
1010

11-
For the last line of text, it should be left-justified and no extra space is inserted between words.
11+
For the last line of text, it should be left-justified, and no extra space is inserted between words.
1212

1313
**Note:**
1414

1515
* A word is defined as a character sequence consisting of non-space characters only.
16-
* Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
16+
* Each word's length is guaranteed to be greater than `0` and not exceed `maxWidth`.
1717
* The input array `words` contains at least one word.
1818

1919
**Example 1:**
@@ -28,7 +28,7 @@ For the last line of text, it should be left-justified and no extra space is ins
2828

2929
**Output:** [ "What must be", "acknowledgment ", "shall be " ]
3030

31-
**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified becase it contains only one word.
31+
**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified because it contains only one word.
3232

3333
**Example 3:**
3434

0 commit comments

Comments
 (0)