Skip to content

Commit d91801c

Browse files
committed
deploy: 85429f1
1 parent f39b4d8 commit d91801c

File tree

7 files changed

+286
-146
lines changed

7 files changed

+286
-146
lines changed

en/lc/2600/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64727,9 +64727,9 @@
6472764727
<ul class="md-nav__list">
6472864728

6472964729
<li class="md-nav__item">
64730-
<a href="#solution-1" class="md-nav__link">
64730+
<a href="#solution-1-greedy" class="md-nav__link">
6473164731
<span class="md-ellipsis">
64732-
Solution 1
64732+
Solution 1: Greedy
6473364733
</span>
6473464734
</a>
6473564735

@@ -87256,7 +87256,15 @@ <h2 id="description">Description</h2>
8725687256
<h2 id="solutions">Solutions</h2>
8725787257
<!-- solution:start -->
8725887258

87259-
<h3 id="solution-1">Solution 1</h3>
87259+
<h3 id="solution-1-greedy">Solution 1: Greedy</h3>
87260+
<p>According to the problem description, we should take as many items marked as <span class="arithmatex">\(1\)</span> as possible, then take items marked as <span class="arithmatex">\(0\)</span>, and finally take items marked as <span class="arithmatex">\(-1\)</span>.</p>
87261+
<p>Thus:</p>
87262+
<ul>
87263+
<li>If the number of items marked as <span class="arithmatex">\(1\)</span> in the bag is greater than or equal to <span class="arithmatex">\(k\)</span>, we take <span class="arithmatex">\(k\)</span> items, and the sum of the numbers is <span class="arithmatex">\(k\)</span>.</li>
87264+
<li>If the number of items marked as <span class="arithmatex">\(1\)</span> is less than <span class="arithmatex">\(k\)</span>, we take <span class="arithmatex">\(\textit{numOnes}\)</span> items, resulting in a sum of <span class="arithmatex">\(\textit{numOnes}\)</span>. If the number of items marked as <span class="arithmatex">\(0\)</span> is greater than or equal to <span class="arithmatex">\(k - \textit{numOnes}\)</span>, we take <span class="arithmatex">\(k - \textit{numOnes}\)</span> more items, keeping the sum at <span class="arithmatex">\(\textit{numOnes}\)</span>.</li>
87265+
<li>Otherwise, we take <span class="arithmatex">\(k - \textit{numOnes} - \textit{numZeros}\)</span> items from those marked as <span class="arithmatex">\(-1\)</span>, resulting in a sum of <span class="arithmatex">\(\textit{numOnes} - (k - \textit{numOnes} - \textit{numZeros})\)</span>.</li>
87266+
</ul>
87267+
<p>The time complexity is <span class="arithmatex">\(O(1)\)</span>, and the space complexity is <span class="arithmatex">\(O(1)\)</span>.</p>
8726087268
<div class="tabbed-set tabbed-alternate" data-tabs="1:7"><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" /><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">C#</label></div>
8726187269
<div class="tabbed-content">
8726287270
<div class="tabbed-block">

en/lc/960/index.html

Lines changed: 119 additions & 70 deletions
Large diffs are not rendered by default.

en/search/search_index.json

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

lc/2600/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92058,8 +92058,8 @@ <h3 id="_3">方法一:贪心</h3>
9205892058
<p>因此:</p>
9205992059
<ul>
9206092060
<li>如果袋子中的物品标记为 <span class="arithmatex">\(1\)</span> 的数量大于等于 <span class="arithmatex">\(k\)</span>,那么取 <span class="arithmatex">\(k\)</span> 件物品,数字之和为 <span class="arithmatex">\(k\)</span>;</li>
92061-
<li>如果袋子中的物品标记为 <span class="arithmatex">\(1\)</span> 的数量小于 <span class="arithmatex">\(k\)</span>,那么取 <span class="arithmatex">\(numOnes\)</span> 件物品,数字之和为 <span class="arithmatex">\(numOnes\)</span>;如果标记为 <span class="arithmatex">\(0\)</span> 的物品数量大于等于 <span class="arithmatex">\(k - numOnes\)</span>,那么再取 <span class="arithmatex">\(k - numOnes\)</span> 件物品,数字之和还是 <span class="arithmatex">\(numOnes\)</span>;</li>
92062-
<li>否则,我们再从标记为 <span class="arithmatex">\(-1\)</span> 的物品中取 <span class="arithmatex">\(k - numOnes - numZeros\)</span> 件物品,数字之和为 <span class="arithmatex">\(numOnes - (k - numOnes - numZeros)\)</span>。</li>
92061+
<li>如果袋子中的物品标记为 <span class="arithmatex">\(1\)</span> 的数量小于 <span class="arithmatex">\(k\)</span>,那么取 <span class="arithmatex">\(\textit{numOnes}\)</span> 件物品,数字之和为 <span class="arithmatex">\(\textit{numOnes}\)</span>;如果标记为 <span class="arithmatex">\(0\)</span> 的物品数量大于等于 <span class="arithmatex">\(k - \textit{numOnes}\)</span>,那么再取 <span class="arithmatex">\(k - \textit{numOnes}\)</span> 件物品,数字之和还是 <span class="arithmatex">\(\textit{numOnes}\)</span>;</li>
92062+
<li>否则,我们再从标记为 <span class="arithmatex">\(-1\)</span> 的物品中取 <span class="arithmatex">\(k - \textit{numOnes} - \textit{numZeros}\)</span> 件物品,数字之和为 <span class="arithmatex">\(\textit{numOnes} - (k - \textit{numOnes} - \textit{numZeros})\)</span>。</li>
9206392063
</ul>
9206492064
<p>时间复杂度 <span class="arithmatex">\(O(1)\)</span>,空间复杂度 <span class="arithmatex">\(O(1)\)</span>。</p>
9206592065
<div class="tabbed-set tabbed-alternate" data-tabs="1:7"><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" /><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">C#</label></div>

lc/416/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92682,6 +92682,41 @@ <h3 id="_4">方法二:动态规划(空间优化)</h3>
9268292682

9268392683

9268492684

92685+
<aside class="md-source-file">
92686+
92687+
92688+
92689+
92690+
92691+
<span class="md-source-file__fact">
92692+
92693+
92694+
<span class="md-icon" title="贡献者">
92695+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34-.46-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.87 1.52 2.34 1.07 2.91.83.09-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.92 0-1.11.38-2 1.03-2.71-.1-.25-.45-1.29.1-2.64 0 0 .84-.27 2.75 1.02.79-.22 1.65-.33 2.5-.33s1.71.11 2.5.33c1.91-1.29 2.75-1.02 2.75-1.02.55 1.35.2 2.39.1 2.64.65.71 1.03 1.6 1.03 2.71 0 3.82-2.34 4.66-4.57 4.91.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2"/></svg>
92696+
</span>
92697+
<span>GitHub</span>
92698+
92699+
92700+
<nav>
92701+
92702+
<a href="https://github.com/yanglbme" class="md-author" title="@yanglbme">
92703+
92704+
<img src="https://avatars.githubusercontent.com/u/21008209?v=4&size=72" alt="yanglbme">
92705+
</a>
92706+
92707+
<a href="https://github.com/xzhseh" class="md-author" title="@xzhseh">
92708+
92709+
<img src="https://avatars.githubusercontent.com/u/91381303?v=4&size=72" alt="xzhseh">
92710+
</a>
92711+
92712+
92713+
92714+
</nav>
92715+
</span>
92716+
92717+
92718+
</aside>
92719+
9268592720

9268692721

9268792722

0 commit comments

Comments
 (0)