Skip to content

Commit 1cdef49

Browse files
committed
0053-maximum-subarray.md Fixed Java solution.
1 parent 9ef7bb9 commit 1cdef49

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

0053-maximum-subarray.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@ dp = [-2, 1, -2, 4, 3, 5, 6, 1, 5]
4747
* Time: `O(n)`.
4848
* Space: `O(n)`.
4949

50-
## Java
51-
52-
```java
53-
class Solution {
54-
int[] dp = nums.clone();
55-
int result = dp[0];
56-
57-
for (int i = 1; i < dp.length; i++) {
58-
dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]);
59-
if (dp[i] > result) result = dp[i];
60-
}
61-
62-
return result; // or 'return Arrays.stream(dp).max().getAsInt();'
63-
}
64-
```
65-
6650
## Python
6751
```python
6852
class Solution:
@@ -91,6 +75,23 @@ public:
9175
};
9276
```
9377
78+
## Java
79+
```java
80+
class Solution {
81+
public int maxSubArray(int[] nums) {
82+
int[] dp = nums.clone();
83+
int result = dp[0];
84+
85+
for (int i = 1; i < dp.length; i++) {
86+
dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]);
87+
if (dp[i] > result) result = dp[i];
88+
}
89+
90+
return result; // or 'return Arrays.stream(dp).max().getAsInt();'
91+
}
92+
}
93+
```
94+
9495
## C#
9596
```c#
9697
public class Solution {

0583-delete-operation-for-two-strings.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ After initialized, the 'dp' array would be:
3838
# e 2 0 0 0
3939
# a 3 0 0 0
4040
```
41-
* `dp[0][j] = j`, because `dp[0]` represents the empty string, and the number of steps is just the number of chars to be deleted
41+
* `dp[0][j] = j`, because `dp[0]` represents the empty string, and the number of steps is just the number of chars to be deleted.
4242
* `dp[i][0] = i`, the reason is the same as previous line, yet in vertical direction.
4343
3. Determine the `dp` array's recurrence formula
4444
```

0 commit comments

Comments
 (0)