Skip to content

feat: add weekly contest 438 #4101

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

Merged
merged 2 commits into from
Feb 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ tags:
<strong>输出:</strong>
[null,false,true]
<strong>解释:</strong>
FindElements findElements = new FindElements([-1,null,-1]);
findElements.find(1); // return False
FindElements findElements = new FindElements([-1,null,-1]);
findElements.find(1); // return False
findElements.find(2); // return True </pre>

<p><strong class="example">示例 2:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ tags:
<strong>Output</strong>
[null,false,true]
<strong>Explanation</strong>
FindElements findElements = new FindElements([-1,null,-1]);
findElements.find(1); // return False
FindElements findElements = new FindElements([-1,null,-1]);
findElements.find(1); // return False
findElements.find(2); // return True </pre>

<p><strong class="example">Example 2:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3461.Check%20If%20Digits%20Are%20Equal%20in%20String%20After%20Operations%20I/README.md
---

<!-- problem:start -->

# [3461. 判断操作后字符串中的数字是否相等 I](https://leetcode.cn/problems/check-if-digits-are-equal-in-string-after-operations-i)

[English Version](/solution/3400-3499/3461.Check%20If%20Digits%20Are%20Equal%20in%20String%20After%20Operations%20I/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你一个由数字组成的字符串 <code>s</code>&nbsp;。重复执行以下操作,直到字符串恰好包含&nbsp;<strong>两个&nbsp;</strong>数字:</p>

<ul>
<li>从第一个数字开始,对于 <code>s</code> 中的每一对连续数字,计算这两个数字的和&nbsp;<strong>模&nbsp;</strong>10。</li>
<li>用计算得到的新数字依次替换 <code>s</code>&nbsp;的每一个字符,并保持原本的顺序。</li>
</ul>

<p>如果 <code>s</code>&nbsp;最后剩下的两个数字 <strong>相同</strong> ,返回 <code>true</code>&nbsp;。否则,返回 <code>false</code>。</p>

<p>&nbsp;</p>

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

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "3902"</span></p>

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

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

<ul>
<li>一开始,<code>s = "3902"</code></li>
<li>第一次操作:
<ul>
<li><code>(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2</code></li>
<li><code>(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9</code></li>
<li><code>(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2</code></li>
<li><code>s</code> 变为 <code>"292"</code></li>
</ul>
</li>
<li>第二次操作:
<ul>
<li><code>(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1</code></li>
<li><code>(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1</code></li>
<li><code>s</code> 变为 <code>"11"</code></li>
</ul>
</li>
<li>由于 <code>"11"</code> 中的数字相同,输出为 <code>true</code>。</li>
</ul>
</div>

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

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "34789"</span></p>

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

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

<ul>
<li>一开始,<code>s = "34789"</code>。</li>
<li>第一次操作后,<code>s = "7157"</code>。</li>
<li>第二次操作后,<code>s = "862"</code>。</li>
<li>第三次操作后,<code>s = "48"</code>。</li>
<li>由于 <code>'4' != '8'</code>,输出为 <code>false</code>。</li>
</ul>

<p>&nbsp;</p>
</div>

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

<ul>
<li><code>3 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> 仅由数字组成。</li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3461.Check%20If%20Digits%20Are%20Equal%20in%20String%20After%20Operations%20I/README_EN.md
---

<!-- problem:start -->

# [3461. Check If Digits Are Equal in String After Operations I](https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-i)

[中文文档](/solution/3400-3499/3461.Check%20If%20Digits%20Are%20Equal%20in%20String%20After%20Operations%20I/README.md)

## Description

<!-- description:start -->

<p>You are given a string <code>s</code> consisting of digits. Perform the following operation repeatedly until the string has <strong>exactly</strong> two digits:</p>

<ul>
<li>For each pair of consecutive digits in <code>s</code>, starting from the first digit, calculate a new digit as the sum of the two digits <strong>modulo</strong> 10.</li>
<li>Replace <code>s</code> with the sequence of newly calculated digits, <em>maintaining the order</em> in which they are computed.</li>
</ul>

<p>Return <code>true</code> if the final two digits in <code>s</code> are the <strong>same</strong>; otherwise, return <code>false</code>.</p>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;3902&quot;</span></p>

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

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

<ul>
<li>Initially, <code>s = &quot;3902&quot;</code></li>
<li>First operation:
<ul>
<li><code>(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2</code></li>
<li><code>(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9</code></li>
<li><code>(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2</code></li>
<li><code>s</code> becomes <code>&quot;292&quot;</code></li>
</ul>
</li>
<li>Second operation:
<ul>
<li><code>(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1</code></li>
<li><code>(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1</code></li>
<li><code>s</code> becomes <code>&quot;11&quot;</code></li>
</ul>
</li>
<li>Since the digits in <code>&quot;11&quot;</code> are the same, the output is <code>true</code>.</li>
</ul>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;34789&quot;</span></p>

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

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

<ul>
<li>Initially, <code>s = &quot;34789&quot;</code>.</li>
<li>After the first operation, <code>s = &quot;7157&quot;</code>.</li>
<li>After the second operation, <code>s = &quot;862&quot;</code>.</li>
<li>After the third operation, <code>s = &quot;48&quot;</code>.</li>
<li>Since <code>&#39;4&#39; != &#39;8&#39;</code>, the output is <code>false</code>.</li>
</ul>
</div>

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

<ul>
<li><code>3 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> consists of only digits.</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 -->
111 changes: 111 additions & 0 deletions solution/3400-3499/3462.Maximum Sum With at Most K Elements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3462.Maximum%20Sum%20With%20at%20Most%20K%20Elements/README.md
---

<!-- problem:start -->

# [3462. 提取至多 K 个元素的最大总和](https://leetcode.cn/problems/maximum-sum-with-at-most-k-elements)

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

## 题目描述

<!-- description:start -->

<p data-pm-slice="1 3 []">给你一个大小为 <code>n x m</code>&nbsp;的二维矩阵&nbsp;<code>grid</code>&nbsp;,以及一个长度为 <code>n</code>&nbsp;的整数数组&nbsp;<code>limits</code>&nbsp;,和一个整数&nbsp;<code>k</code>&nbsp;。你的目标是从矩阵 <code>grid</code> 中提取出&nbsp;<strong>至多</strong> <code>k</code>&nbsp;个元素,并计算这些元素的最大总和,提取时需满足以下限制<b>:</b></p>

<ul data-spread="false">
<li>
<p>从 <code>grid</code>&nbsp;的第 <code>i</code> 行提取的元素数量不超过 <code>limits[i]</code> 。</p>
</li>
</ul>

<p data-pm-slice="1 1 []">返回最大总和。</p>

<p>&nbsp;</p>

<p><b>示例 1:</b></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[1,2],[3,4]], limits = [1,2], k = 2</span></p>

<p><span class="example-io"><b>输出:</b>7</span></p>

<p><b>解释:</b></p>

<ul>
<li>从第 2 行提取至多 2 个元素,取出 4 和 3 。</li>
<li>至多提取 2 个元素时的最大总和&nbsp;<code>4 + 3 = 7</code>&nbsp;。</li>
</ul>
</div>

<p><b>示例 2:</b></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b></span><span class="example-io">grid = [[5,3,7],[8,2,6]], limits = [2,2], k = 3</span></p>

<p><span class="example-io"><b>输出:</b></span><span class="example-io">21</span></p>

<p><b>解释:</b></p>

<ul>
<li>从第 1&nbsp;行提取至多 2 个元素,取出 7 。</li>
<li>从第 2 行提取至多 2 个元素,取出&nbsp;8 和 6 。</li>
<li>至多提取 3&nbsp;个元素时的最大总和 <code>7 + 8 + 6 = 21</code>&nbsp;。</li>
</ul>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>n == grid.length == limits.length</code></li>
<li><code>m == grid[i].length</code></li>
<li><code>1 &lt;= n, m &lt;= 500</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= limits[i] &lt;= m</code></li>
<li><code>0 &lt;= k &lt;= min(n * m, sum(limits))</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