Skip to content

Commit 1bc7c34

Browse files
committed
deploy: 430ebdc
1 parent c0065af commit 1bc7c34

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

en/lc/53/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80364,17 +80364,17 @@ <h2 id="solutions">Solutions</h2>
8036480364
<!-- solution:start -->
8036580365

8036680366
<h3 id="solution-1-dynamic-programming">Solution 1: Dynamic Programming</h3>
80367-
<p>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 &lt; n} f[i]$.</p>
80368-
<p>Consider $f[i]$, where $i \geq 1$, its state transition equation is:</p>
80367+
<p>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 &lt; n} f[i]$.</p>
80368+
<p>Consider $f[i]$ for $i \geq 1$. Its state transition equation is:</p>
8036980369
<p>$$
80370-
f[i] = \max { f[i - 1] + nums[i], nums[i] }
80370+
f[i] = \max(f[i - 1] + \textit{nums}[i], \textit{nums}[i])
8037180371
$$</p>
80372-
<p>Which is also:</p>
80372+
<p>That is:</p>
8037380373
<p>$$
80374-
f[i] = \max { f[i - 1], 0 } + nums[i]
80374+
f[i] = \max(f[i - 1], 0) + \textit{nums}[i]
8037580375
$$</p>
80376-
<p>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 &lt; n} f$.</p>
80377-
<p>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.</p>
80376+
<p>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 &lt; n} f$.</p>
80377+
<p>The time complexity is $O(n)$, where $n$ is the length of the array $\textit{nums}$. The space complexity is $O(1)$.</p>
8037880378
<div class="tabbed-set tabbed-alternate" data-tabs="1:8"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label><label for="__tabbed_1_6">Rust</label><label for="__tabbed_1_7">JavaScript</label><label for="__tabbed_1_8">C#</label></div>
8037980379
<div class="tabbed-content">
8038080380
<div class="tabbed-block">

en/search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lc/53/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84967,17 +84967,17 @@ <h2 id="_2">解法</h2>
8496784967
<!-- solution:start -->
8496884968

8496984969
<h3 id="_3">方法一:动态规划</h3>
84970-
<p>我们定义 $f[i]$ 表示以元素 $nums[i]$ 为结尾的连续子数组的最大和,初始时 $f[0] = nums[0]$,那么最终我们要求的答案即为 $\max_{0 \leq i &lt; n} f[i]$。</p>
84970+
<p>我们定义 $f[i]$ 表示以元素 $\textit{nums}[i]$ 为结尾的连续子数组的最大和,初始时 $f[0] = \textit{nums}[0]$,那么最终我们要求的答案即为 $\max_{0 \leq i &lt; n} f[i]$。</p>
8497184971
<p>考虑 $f[i]$,其中 $i \geq 1$,它的状态转移方程为:</p>
8497284972
<p>$$
84973-
f[i] = \max { f[i - 1] + nums[i], nums[i] }
84973+
f[i] = \max(f[i - 1] + \textit{nums}[i], \textit{nums}[i])
8497484974
$$</p>
8497584975
<p>也即:</p>
8497684976
<p>$$
84977-
f[i] = \max { f[i - 1], 0 } + nums[i]
84977+
f[i] = \max(f[i - 1], 0) + \textit{nums}[i]
8497884978
$$</p>
8497984979
<p>由于 $f[i]$ 只与 $f[i - 1]$ 有关系,因此我们可以只用一个变量 $f$ 来维护对于当前 $f[i]$ 的值是多少,然后进行状态转移即可。答案为 $\max_{0 \leq i &lt; n} f$。</p>
84980-
<p>时间复杂度 $O(n)$,其中 $n$ 为数组 $nums$ 的长度。我们只需要遍历一遍数组即可求得答案。空间复杂度 $O(1)$,我们只需要常数空间存放若干变量。</p>
84980+
<p>时间复杂度 $O(n)$,其中 $n$ 为数组 $\textit{nums}$ 的长度。空间复杂度 $O(1)$。</p>
8498184981
<div class="tabbed-set tabbed-alternate" data-tabs="1:8"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label><label for="__tabbed_1_6">Rust</label><label for="__tabbed_1_7">JavaScript</label><label for="__tabbed_1_8">C#</label></div>
8498284982
<div class="tabbed-content">
8498384983
<div class="tabbed-block">

search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)