Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 430ebdc

Browse files
fix: update solutions to lc problem: No.53 (#3740)
close #3734
1 parent 5d79d9f commit 430ebdc

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

‎solution/0000-0099/0053.Maximum Subarray/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,23 @@ tags:
6767

6868
### 方法一:动态规划
6969

70-
我们定义 $f[i]$ 表示以元素 $nums[i]$ 为结尾的连续子数组的最大和,初始时 $f[0] = nums[0],ドル那么最终我们要求的答案即为 $\max_{0 \leq i < n} f[i]$。
70+
我们定义 $f[i]$ 表示以元素 $\textit{nums}[i]$ 为结尾的连续子数组的最大和,初始时 $f[0] = \textit{nums}[0],ドル那么最终我们要求的答案即为 $\max_{0 \leq i < n} f[i]$。
7171

7272
考虑 $f[i],ドル其中 $i \geq 1,ドル它的状态转移方程为:
7373

7474
$$
75-
f[i] = \max \{ f[i - 1] + nums[i], nums[i] \}
75+
f[i] = \max(f[i - 1] + \textit{nums}[i], \textit{nums}[i])
7676
$$
7777

7878
也即:
7979

8080
$$
81-
f[i] = \max \{ f[i - 1], 0 \} + nums[i]
81+
f[i] = \max(f[i - 1], 0) + \textit{nums}[i]
8282
$$
8383

8484
由于 $f[i]$ 只与 $f[i - 1]$ 有关系,因此我们可以只用一个变量 $f$ 来维护对于当前 $f[i]$ 的值是多少,然后进行状态转移即可。答案为 $\max_{0 \leq i < n} f$。
8585

86-
时间复杂度 $O(n),ドル其中 $n$ 为数组 $nums$ 的长度。我们只需要遍历一遍数组即可求得答案。空间复杂度 $O(1)$,我们只需要常数空间存放若干变量
86+
时间复杂度 $O(n),ドル其中 $n$ 为数组 $\textit{nums}$ 的长度。空间复杂度 $O(1)$。
8787

8888
<!-- tabs:start -->
8989

‎solution/0000-0099/0053.Maximum Subarray/README_EN.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ tags:
6464

6565
### Solution 1: Dynamic Programming
6666

67-
We define $f[i]$ to represent the maximum sum of the continuous subarray ending with the element $nums[i]$. Initially, $f[0] = nums[0]$. The final answer we are looking for is $\max_{0 \leq i < n} f[i]$.
67+
We define $f[i]$ to represent the maximum sum of a contiguous subarray ending at element $\textit{nums}[i]$. Initially, $f[0] = \textit{nums}[0]$. The final answer we seek is $\max_{0 \leq i < n} f[i]$.
6868

69-
Consider $f[i]$, where $i \geq 1$, its state transition equation is:
69+
Consider $f[i]$ for $i \geq 1$. Its state transition equation is:
7070

7171
$$
72-
f[i] = \max \{ f[i - 1] + nums[i], nums[i] \}
72+
f[i] = \max(f[i - 1] + \textit{nums}[i], \textit{nums}[i])
7373
$$
7474

75-
Which is also:
75+
That is:
7676

7777
$$
78-
f[i] = \max \{ f[i - 1], 0 \} + nums[i]
78+
f[i] = \max(f[i - 1], 0) + \textit{nums}[i]
7979
$$
8080

81-
Since $f[i]$ is only related to $f[i - 1],ドル we can use a single variable $f$ to maintain the current value of $f[i]$, and then perform state transition. The answer is $\max_{0 \leq i < n} f$.
81+
Since $f[i]$ is only related to $f[i - 1],ドル we can use a single variable $f$ to maintain the current value of $f[i]$ and perform the state transition. The answer is $\max_{0 \leq i < n} f$.
8282

83-
The time complexity is $O(n),ドル where $n$ is the length of the array $nums$. We only need to traverse the array once to get the answer. The space complexity is $O(1)$, we only need constant space to store several variables.
83+
The time complexity is $O(n),ドル where $n$ is the length of the array $\textit{nums}$. The space complexity is $O(1)$.
8484

8585
<!-- tabs:start -->
8686

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /