Skip to content

Commit d50db4e

Browse files
committed
deploy: b1fe6a2
1 parent e78ee14 commit d50db4e

File tree

6 files changed

+398
-21
lines changed

6 files changed

+398
-21
lines changed

en/lc/1526/index.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39034,9 +39034,9 @@
3903439034
<ul class="md-nav__list">
3903539035

3903639036
<li class="md-nav__item">
39037-
<a href="#solution-1" class="md-nav__link">
39037+
<a href="#solution-1-dynamic-programming" class="md-nav__link">
3903839038
<span class="md-ellipsis">
39039-
Solution 1
39039+
Solution 1: Dynamic Programming
3904039040
</span>
3904139041
</a>
3904239042

@@ -77567,7 +77567,16 @@ <h2 id="description">Description</h2>
7756777567
<h2 id="solutions">Solutions</h2>
7756877568
<!-- solution:start -->
7756977569

77570-
<h3 id="solution-1">Solution 1</h3>
77570+
<h3 id="solution-1-dynamic-programming">Solution 1: Dynamic Programming</h3>
77571+
<p>We define $f[i]$ as the minimum number of operations required to obtain $target[0,..i]$, initially setting $f[0] = target[0]$.</p>
77572+
<p>For $target[i]$, if $target[i] \leq target[i-1]$, then $f[i] = f[i-1]$; otherwise, $f[i] = f[i-1] + target[i] - target[i-1]$.</p>
77573+
<p>The final answer is $f[n-1]$.</p>
77574+
<p>We notice that $f[i]$ only depends on $f[i-1]$, so we can maintain the operation count using just one variable.</p>
77575+
<p>The time complexity is $O(n)$, where $n$ is the length of the array $target$. The space complexity is $O(1)$.</p>
77576+
<p>Similar problems:</p>
77577+
<ul>
77578+
<li><a href="https://github.com/doocs/leetcode/blob/main/solution/3200-3299/3229.Minimum%20Operations%20to%20Make%20Array%20Equal%20to%20Target/README_EN.md">3229. Minimum Operations to Make Array Equal to Target</a></li>
77579+
</ul>
7757177580
<div class="tabbed-set tabbed-alternate" data-tabs="1:5"><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" /><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></div>
7757277581
<div class="tabbed-content">
7757377582
<div class="tabbed-block">

0 commit comments

Comments
 (0)