Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add weekly contest 440 #4138

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions solution/2200-2299/2227.Encrypt and Decrypt Strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ tags:

<strong>解释:</strong>
Encrypter encrypter = new Encrypter([['a', 'b', 'c', 'd'], ["ei", "zf", "ei", "am"], ["abcd", "acbd", "adbc", "badc", "dacb", "cadb", "cbda", "abad"]);
encrypter.encrypt("abcd"); // 返回 "eizfeiam"。
encrypter.encrypt("abcd"); // 返回 "eizfeiam"。
&nbsp; // 'a' 映射为 "ei",'b' 映射为 "zf",'c' 映射为 "ei",'d' 映射为 "am"。
encrypter.decrypt("eizfeiam"); // return 2.
// "ei" 可以映射为 'a' 或 'c',"zf" 映射为 'b',"am" 映射为 'd'。
// 因此,解密后可以得到的字符串是 "abad","cbad","abcd" 和 "cbcd"。
encrypter.decrypt("eizfeiam"); // return 2.
// "ei" 可以映射为 'a' 或 'c',"zf" 映射为 'b',"am" 映射为 'd'。
// 因此,解密后可以得到的字符串是 "abad","cbad","abcd" 和 "cbcd"。
// 其中 2 个字符串,"abad" 和 "abcd",在 dictionary 中出现,所以答案是 2 。
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ tags:

<strong>Explanation</strong>
Encrypter encrypter = new Encrypter([[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;], [&quot;ei&quot;, &quot;zf&quot;, &quot;ei&quot;, &quot;am&quot;], [&quot;abcd&quot;, &quot;acbd&quot;, &quot;adbc&quot;, &quot;badc&quot;, &quot;dacb&quot;, &quot;cadb&quot;, &quot;cbda&quot;, &quot;abad&quot;]);
encrypter.encrypt(&quot;abcd&quot;); // return &quot;eizfeiam&quot;.
encrypter.encrypt(&quot;abcd&quot;); // return &quot;eizfeiam&quot;.
&nbsp; // &#39;a&#39; maps to &quot;ei&quot;, &#39;b&#39; maps to &quot;zf&quot;, &#39;c&#39; maps to &quot;ei&quot;, and &#39;d&#39; maps to &quot;am&quot;.
encrypter.decrypt(&quot;eizfeiam&quot;); // return 2.
// &quot;ei&quot; can map to &#39;a&#39; or &#39;c&#39;, &quot;zf&quot; maps to &#39;b&#39;, and &quot;am&quot; maps to &#39;d&#39;.
// Thus, the possible strings after decryption are &quot;abad&quot;, &quot;cbad&quot;, &quot;abcd&quot;, and &quot;cbcd&quot;.
encrypter.decrypt(&quot;eizfeiam&quot;); // return 2.
// &quot;ei&quot; can map to &#39;a&#39; or &#39;c&#39;, &quot;zf&quot; maps to &#39;b&#39;, and &quot;am&quot; maps to &#39;d&#39;.
// Thus, the possible strings after decryption are &quot;abad&quot;, &quot;cbad&quot;, &quot;abcd&quot;, and &quot;cbcd&quot;.
// 2 of those strings, &quot;abad&quot; and &quot;abcd&quot;, appear in dictionary, so the answer is 2.
</pre>

Expand Down
115 changes: 115 additions & 0 deletions solution/3400-3499/3477.Fruits Into Baskets II/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3477.Fruits%20Into%20Baskets%20II/README.md
---

<!-- problem:start -->

# [3477. 将水果放入篮子 II](https://leetcode.cn/problems/fruits-into-baskets-ii)

[English Version](/solution/3400-3499/3477.Fruits%20Into%20Baskets%20II/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你两个长度为 <code>n</code>&nbsp;的整数数组,<code>fruits</code> 和 <code>baskets</code>,其中 <code>fruits[i]</code> 表示第 <code>i</code>&nbsp;种水果的 <strong>数量</strong>,<code>baskets[j]</code> 表示第 <code>j</code>&nbsp;个篮子的 <strong>容量</strong>。</p>

<p>你需要对 <code>fruits</code> 数组从左到右按照以下规则放置水果:</p>

<ul>
<li>每种水果必须放入第一个 <strong>容量大于等于</strong> 该水果数量的 <strong>最左侧可用篮子</strong> 中。</li>
<li>每个篮子只能装 <b>一种</b> 水果。</li>
<li>如果一种水果 <b>无法放入</b> 任何篮子,它将保持 <b>未放置</b>。</li>
</ul>

<p>返回所有可能分配完成后,剩余未放置的水果种类的数量。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">fruits = [4,2,5], baskets = [3,5,4]</span></p>

<p><strong>输出:</strong> <span class="example-io">1</span></p>

<p><strong>解释:</strong></p>

<ul>
<li><code>fruits[0] = 4</code> 放入 <code>baskets[1] = 5</code>。</li>
<li><code>fruits[1] = 2</code> 放入 <code>baskets[0] = 3</code>。</li>
<li><code>fruits[2] = 5</code> 无法放入 <code>baskets[2] = 4</code>。</li>
</ul>

<p>由于有一种水果未放置,我们返回 1。</p>
</div>

<p><strong class="example">示例 2</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">fruits = [3,6,1], baskets = [6,4,7]</span></p>

<p><strong>输出:</strong> <span class="example-io">0</span></p>

<p><strong>解释:</strong></p>

<ul>
<li><code>fruits[0] = 3</code> 放入 <code>baskets[0] = 6</code>。</li>
<li><code>fruits[1] = 6</code> 无法放入 <code>baskets[1] = 4</code>(容量不足),但可以放入下一个可用的篮子 <code>baskets[2] = 7</code>。</li>
<li><code>fruits[2] = 1</code> 放入 <code>baskets[1] = 4</code>。</li>
</ul>

<p>由于所有水果都已成功放置,我们返回 0。</p>
</div>

<p>&nbsp;</p>

<p><b>提示:</b></p>

<ul>
<li><code>n == fruits.length == baskets.length</code></li>
<li><code>1 &lt;= n &lt;= 100</code></li>
<li><code>1 &lt;= fruits[i], baskets[i] &lt;= 1000</code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
113 changes: 113 additions & 0 deletions solution/3400-3499/3477.Fruits Into Baskets II/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3477.Fruits%20Into%20Baskets%20II/README_EN.md
---

<!-- problem:start -->

# [3477. Fruits Into Baskets II](https://leetcode.com/problems/fruits-into-baskets-ii)

[中文文档](/solution/3400-3499/3477.Fruits%20Into%20Baskets%20II/README.md)

## Description

<!-- description:start -->

<p>You are given two arrays of integers, <code>fruits</code> and <code>baskets</code>, each of length <code>n</code>, where <code>fruits[i]</code> represents the <strong>quantity</strong> of the <code>i<sup>th</sup></code> type of fruit, and <code>baskets[j]</code> represents the <strong>capacity</strong> of the <code>j<sup>th</sup></code> basket.</p>

<p>From left to right, place the fruits according to these rules:</p>

<ul>
<li>Each fruit type must be placed in the <strong>leftmost available basket</strong> with a capacity <strong>greater than or equal</strong> to the quantity of that fruit type.</li>
<li>Each basket can hold <b>only one</b> type of fruit.</li>
<li>If a fruit type <b>cannot be placed</b> in any basket, it remains <b>unplaced</b>.</li>
</ul>

<p>Return the number of fruit types that remain unplaced after all possible allocations are made.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">fruits = [4,2,5], baskets = [3,5,4]</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>

<p><strong>Explanation:</strong></p>

<ul>
<li><code>fruits[0] = 4</code> is placed in <code>baskets[1] = 5</code>.</li>
<li><code>fruits[1] = 2</code> is placed in <code>baskets[0] = 3</code>.</li>
<li><code>fruits[2] = 5</code> cannot be placed in <code>baskets[2] = 4</code>.</li>
</ul>

<p>Since one fruit type remains unplaced, we return 1.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">fruits = [3,6,1], baskets = [6,4,7]</span></p>

<p><strong>Output:</strong> <span class="example-io">0</span></p>

<p><strong>Explanation:</strong></p>

<ul>
<li><code>fruits[0] = 3</code> is placed in <code>baskets[0] = 6</code>.</li>
<li><code>fruits[1] = 6</code> cannot be placed in <code>baskets[1] = 4</code> (insufficient capacity) but can be placed in the next available basket, <code>baskets[2] = 7</code>.</li>
<li><code>fruits[2] = 1</code> is placed in <code>baskets[1] = 4</code>.</li>
</ul>

<p>Since all fruits are successfully placed, we return 0.</p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>n == fruits.length == baskets.length</code></li>
<li><code>1 &lt;= n &lt;= 100</code></li>
<li><code>1 &lt;= fruits[i], baskets[i] &lt;= 1000</code></li>
</ul>

<!-- description:end -->

## Solutions

<!-- solution:start -->

### Solution 1

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
107 changes: 107 additions & 0 deletions solution/3400-3499/3478.Choose K Elements With Maximum Sum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3478.Choose%20K%20Elements%20With%20Maximum%20Sum/README.md
---

<!-- problem:start -->

# [3478. 选出和最大的 K 个元素](https://leetcode.cn/problems/choose-k-elements-with-maximum-sum)

[English Version](/solution/3400-3499/3478.Choose%20K%20Elements%20With%20Maximum%20Sum/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你两个整数数组,<code>nums1</code> 和 <code>nums2</code>,长度均为 <code>n</code>,以及一个正整数 <code>k</code> 。</p>

<p>对从 <code>0</code> 到 <code>n - 1</code> 每个下标 <code>i</code> ,执行下述操作:</p>

<ul>
<li>找出所有满足 <code>nums1[j]</code> 小于 <code>nums1[i]</code> 的下标 <code>j</code> 。</li>
<li>从这些下标对应的 <code>nums2[j]</code> 中选出 <strong>至多</strong> <code>k</code> 个,并 <strong>最大化</strong> 这些值的总和作为结果。</li>
</ul>

<p>返回一个长度为 <code>n</code> 的数组 <code>answer</code> ,其中 <code>answer[i]</code> 表示对应下标 <code>i</code> 的结果。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [4,2,1,5,3], nums2 = [10,20,30,40,50], k = 2</span></p>

<p><strong>输出:</strong><span class="example-io">[80,30,0,80,50]</span></p>

<p><strong>解释:</strong></p>

<ul>
<li>对于 <code>i = 0</code> :满足 <code>nums1[j] &lt; nums1[0]</code> 的下标为 <code>[1, 2, 4]</code> ,选出其中值最大的两个,结果为 <code>50 + 30 = 80</code> 。</li>
<li>对于 <code>i = 1</code> :满足 <code>nums1[j] &lt; nums1[1]</code> 的下标为 <code>[2]</code> ,只能选择这个值,结果为 <code>30</code> 。</li>
<li>对于 <code>i = 2</code> :不存在满足 <code>nums1[j] &lt; nums1[2]</code> 的下标,结果为 <code>0</code> 。</li>
<li>对于 <code>i = 3</code> :满足 <code>nums1[j] &lt; nums1[3]</code> 的下标为 <code>[0, 1, 2, 4]</code> ,选出其中值最大的两个,结果为 <code>50 + 30 = 80</code> 。</li>
<li>对于 <code>i = 4</code> :满足 <code>nums1[j] &lt; nums1[4]</code> 的下标为 <code>[1, 2]</code> ,选出其中值最大的两个,结果为 <code>30 + 20 = 50</code> 。</li>
</ul>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [2,2,2,2], nums2 = [3,1,2,3], k = 1</span></p>

<p><strong>输出:</strong><span class="example-io">[0,0,0,0]</span></p>

<p><strong>解释:</strong>由于 <code>nums1</code> 中的所有元素相等,不存在满足条件 <code>nums1[j] &lt; nums1[i]</code>,所有位置的结果都是 0 。</p>
</div>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>n == nums1.length == nums2.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums1[i], nums2[i] &lt;= 10<sup>6</sup></code></li>
<li><code>1 &lt;= k &lt;= n</code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading
Loading