Skip to content

Commit b7685d4

Browse files
committed
deploy: 1a6ab2a
1 parent a52159d commit b7685d4

File tree

8 files changed

+108
-280
lines changed

8 files changed

+108
-280
lines changed

en/lc/189/index.html

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11303,15 +11303,6 @@
1130311303
</span>
1130411304
</a>
1130511305

11306-
</li>
11307-
11308-
<li class="md-nav__item">
11309-
<a href="#solution-2" class="md-nav__link">
11310-
<span class="md-ellipsis">
11311-
Solution 2
11312-
</span>
11313-
</a>
11314-
1131511306
</li>
1131611307

1131711308
</ul>
@@ -81443,7 +81434,7 @@ <h2 id="description">Description</h2>
8144381434
<pre>
8144481435
<strong>Input:</strong> nums = [-1,-100,3,99], k = 2
8144581436
<strong>Output:</strong> [3,99,-1,-100]
81446-
<strong>Explanation:</strong>
81437+
<strong>Explanation:</strong>
8144781438
rotate 1 steps to the right: [99,-1,-100,3]
8144881439
rotate 2 steps to the right: [3,99,-1,-100]
8144981440
</pre>
@@ -81741,25 +81732,6 @@ <h3 id="solution-1-reverse-three-times">Solution 1: Reverse three times</h3>
8174181732
</div>
8174281733
<!-- solution:end -->
8174381734

81744-
<!-- solution:start -->
81745-
81746-
<h3 id="solution-2">Solution 2</h3>
81747-
<div class="tabbed-set tabbed-alternate" data-tabs="2:1"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">Python3</label></div>
81748-
<div class="tabbed-content">
81749-
<div class="tabbed-block">
81750-
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
81751-
<span class="normal">2</span>
81752-
<span class="normal">3</span>
81753-
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">class</span> <span class="nc">Solution</span><span class="p">:</span>
81754-
<span class="k">def</span> <span class="nf">rotate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nums</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">int</span><span class="p">],</span> <span class="n">k</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
81755-
<span class="n">k</span> <span class="o">%=</span> <span class="nb">len</span><span class="p">(</span><span class="n">nums</span><span class="p">)</span>
81756-
<span class="n">nums</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">nums</span><span class="p">[</span><span class="o">-</span><span class="n">k</span><span class="p">:]</span> <span class="o">+</span> <span class="n">nums</span><span class="p">[:</span><span class="o">-</span><span class="n">k</span><span class="p">]</span>
81757-
</code></pre></div></td></tr></table></div>
81758-
</div>
81759-
</div>
81760-
</div>
81761-
<!-- solution:end -->
81762-
8176381735
<!-- problem:end -->
8176481736

8176581737

en/lc/238/index.html

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12332,15 +12332,6 @@
1233212332
</span>
1233312333
</a>
1233412334

12335-
</li>
12336-
12337-
<li class="md-nav__item">
12338-
<a href="#solution-2" class="md-nav__link">
12339-
<span class="md-ellipsis">
12340-
Solution 2
12341-
</span>
12342-
</a>
12343-
1234412335
</li>
1234512336

1234612337
</ul>
@@ -81451,11 +81442,11 @@ <h2 id="solutions">Solutions</h2>
8145181442
<!-- solution:start -->
8145281443

8145381444
<h3 id="solution-1-two-passes">Solution 1: Two Passes</h3>
81454-
<p>We define two variables $left$ and $right$, which represent the product of all elements to the left and right of the current element respectively. Initially, $left=1$, $right=1$. Define an answer array $ans$ of length $n$.</p>
81455-
<p>We first traverse the array from left to right, for the $i$th element we update $ans[i]$ with $left$, then $left$ multiplied by $nums[i]$.</p>
81456-
<p>Then, we traverse the array from right to left, for the $i$th element, we update $ans[i]$ to $ans[i] \times right$, then $right$ multiplied by $nums[i]$.</p>
81457-
<p>After the traversal, the array <code>ans</code> is the answer.</p>
81458-
<p>The time complexity is $O(n)$, where $n$ is the length of the array <code>nums</code>. Ignore the space consumption of the answer array, the space complexity is $O(1)$.</p>
81445+
<p>We define two variables $\textit{left}$ and $\textit{right}$ to represent the product of all elements to the left and right of the current element, respectively. Initially, $\textit{left} = 1$ and $\textit{right} = 1$. We define an answer array $\textit{ans}$ of length $n$.</p>
81446+
<p>First, we traverse the array from left to right. For the $i$-th element, we update $\textit{ans}[i]$ with $\textit{left}$, then multiply $\textit{left}$ by $\textit{nums}[i]$.</p>
81447+
<p>Next, we traverse the array from right to left. For the $i$-th element, we update $\textit{ans}[i]$ to $\textit{ans}[i] \times \textit{right}$, then multiply $\textit{right}$ by $\textit{nums}[i]$.</p>
81448+
<p>After the traversal, we return the answer array $\textit{ans}$.</p>
81449+
<p>The time complexity is $O(n)$, where $n$ is the length of the array $\textit{nums}$. Ignoring the space consumption of the answer array, the space complexity is $O(1)$.</p>
8145981450
<div class="tabbed-set tabbed-alternate" data-tabs="1:9"><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" /><input id="__tabbed_1_9" 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><label for="__tabbed_1_9">PHP</label></div>
8146081451
<div class="tabbed-content">
8146181452
<div class="tabbed-block">
@@ -81752,23 +81743,6 @@ <h3 id="solution-1-two-passes">Solution 1: Two Passes</h3>
8175281743
</div>
8175381744
<!-- solution:end -->
8175481745

81755-
<!-- solution:start -->
81756-
81757-
<h3 id="solution-2">Solution 2</h3>
81758-
<div class="tabbed-set tabbed-alternate" data-tabs="2:1"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">TypeScript</label></div>
81759-
<div class="tabbed-content">
81760-
<div class="tabbed-block">
81761-
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
81762-
<span class="normal">2</span>
81763-
<span class="normal">3</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="kd">function</span><span class="w"> </span><span class="nx">productExceptSelf</span><span class="p">(</span><span class="nx">nums</span><span class="o">:</span><span class="w"> </span><span class="kt">number</span><span class="p">[])</span><span class="o">:</span><span class="w"> </span><span class="kt">number</span><span class="p">[]</span><span class="w"> </span><span class="p">{</span>
81764-
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">nums</span><span class="p">.</span><span class="nx">map</span><span class="p">((</span><span class="nx">_</span><span class="p">,</span><span class="w"> </span><span class="nx">i</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">nums</span><span class="p">.</span><span class="nx">reduce</span><span class="p">((</span><span class="nx">pre</span><span class="p">,</span><span class="w"> </span><span class="nx">val</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">pre</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="p">(</span><span class="nx">i</span><span class="w"> </span><span class="o">===</span><span class="w"> </span><span class="nx">j</span><span class="w"> </span><span class="o">?</span><span class="w"> </span><span class="nx">1</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="kt">val</span><span class="p">),</span><span class="w"> </span><span class="mf">1</span><span class="p">));</span>
81765-
<span class="p">}</span>
81766-
</code></pre></div></td></tr></table></div>
81767-
</div>
81768-
</div>
81769-
</div>
81770-
<!-- solution:end -->
81771-
8177281746
<!-- problem:end -->
8177381747

8177481748

0 commit comments

Comments
 (0)