Skip to content

feat: add new lc problems #4429

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
May 25, 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
106 changes: 106 additions & 0 deletions solution/3500-3599/3556.Sum of Largest Prime Substrings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3556.Sum%20of%20Largest%20Prime%20Substrings/README.md
---

<!-- problem:start -->

# [3556. 最大质数子字符串之和](https://leetcode.cn/problems/sum-of-largest-prime-substrings)

[English Version](/solution/3500-3599/3556.Sum%20of%20Largest%20Prime%20Substrings/README_EN.md)

## 题目描述

<!-- description:start -->

<p data-end="157" data-start="30">给定一个字符串 <code>s</code>,找出可以由其&nbsp;<strong>子字符串&nbsp;</strong>组成的&nbsp;<strong>3个最大的不同质数&nbsp;</strong>的和。</p>

<p data-end="269" data-start="166">返回这些质数的&nbsp;<strong>总和&nbsp;</strong>,如果少于 3 个不同的质数,则返回&nbsp;<strong>所有&nbsp;</strong>不同质数的和。</p>

<p data-end="269" data-start="166">质数是大于 1 且只有两个因数的自然数:1和它本身。</p>

<p data-end="269" data-start="166"><strong>子字符串&nbsp;</strong>是字符串中的一个连续字符序列。&nbsp;</p>

<p data-end="370" data-is-last-node="" data-is-only-node="" data-start="271"><strong data-end="280" data-start="271">注意:</strong>每个质数即使出现在&nbsp;<strong>多个&nbsp;</strong>子字符串中,也只能计算&nbsp;<strong>一次&nbsp;</strong>。此外,将子字符串转换为整数时,忽略任何前导零。</p>

<p>&nbsp;</p>

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

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

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

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

<ul>
<li data-end="136" data-start="16">由 <code>"12234"</code> 的子字符串形成的不同质数为 2 ,3 ,23 ,223 和 1223。</li>
<li data-end="226" data-start="137">最大的 3 个质数是 1223、223 和 23。它们的和是 1469。</li>
</ul>
</div>

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

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

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

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

<ul>
<li data-end="339" data-start="244">由 <code>"111"</code> 的子字符串形成的不同质数是 11。</li>
<li data-end="412" data-is-last-node="" data-start="340">由于只有一个质数,所以结果是 11。</li>
</ul>
</div>

<p>&nbsp;</p>

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

<ul>
<li data-end="39" data-start="18"><code>1 &lt;= s.length &lt;= 10</code></li>
<li data-end="68" data-is-last-node="" data-start="40"><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 -->
104 changes: 104 additions & 0 deletions solution/3500-3599/3556.Sum of Largest Prime Substrings/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3556.Sum%20of%20Largest%20Prime%20Substrings/README_EN.md
---

<!-- problem:start -->

# [3556. Sum of Largest Prime Substrings](https://leetcode.com/problems/sum-of-largest-prime-substrings)

[中文文档](/solution/3500-3599/3556.Sum%20of%20Largest%20Prime%20Substrings/README.md)

## Description

<!-- description:start -->

<p data-end="157" data-start="30">Given a string <code>s</code>, find the sum of the <strong>3 largest unique prime numbers</strong> that can be formed using any of its<strong> substrings</strong>.</p>

<p data-end="269" data-start="166">Return the <strong>sum</strong> of the three largest unique prime numbers that can be formed. If fewer than three exist, return the sum of <strong>all</strong> available primes. If no prime numbers can be formed, return 0.</p>

<p data-end="269" data-start="166">A prime number is a natural number greater than 1 with only two factors, 1 and itself.</p>

<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>

<p data-end="370" data-is-last-node="" data-is-only-node="" data-start="271"><strong data-end="280" data-start="271">Note:</strong> Each prime number should be counted only <strong>once</strong>, even if it appears in <strong>multiple</strong> substrings. Additionally, when converting a substring to an integer, any leading zeros are ignored.</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;12234&quot;</span></p>

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

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

<ul>
<li data-end="136" data-start="16">The unique prime numbers formed from the substrings of <code>&quot;12234&quot;</code> are 2, 3, 23, 223, and 1223.</li>
<li data-end="226" data-start="137">The 3 largest primes are 1223, 223, and 23. Their sum is 1469.</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;111&quot;</span></p>

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

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

<ul>
<li data-end="339" data-start="244">The unique prime number formed from the substrings of <code>&quot;111&quot;</code> is 11.</li>
<li data-end="412" data-is-last-node="" data-start="340">Since there is only one prime number, the sum is 11.</li>
</ul>
</div>

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

<ul>
<li data-end="39" data-start="18"><code>1 &lt;= s.length &lt;= 10</code></li>
<li data-end="68" data-is-last-node="" data-start="40"><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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3557.Find%20Maximum%20Number%20of%20Non%20Intersecting%20Substrings/README.md
---

<!-- problem:start -->

# [3557. 不相交子字符串的最大数量](https://leetcode.cn/problems/find-maximum-number-of-non-intersecting-substrings)

[English Version](/solution/3500-3599/3557.Find%20Maximum%20Number%20of%20Non%20Intersecting%20Substrings/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你一个字符串 <code>word</code>。</p>

<p>返回以&nbsp;<strong>首尾字母相同&nbsp;</strong>且&nbsp;<strong>长度至少为 4&nbsp;</strong>的&nbsp;<strong>不相交子字符串&nbsp;</strong>的最大数量。</p>

<p><strong>子字符串&nbsp;</strong>是字符串中连续的&nbsp;<b>非空&nbsp;</b>字符序列。</p>

<p>&nbsp;</p>

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

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

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

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

<p>两个子字符串是 <code>"abcdea"</code> 和 <code>"fdef"</code>。</p>
</div>

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

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

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

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

<p>唯一的子字符串是 <code>"aaaa"</code>。注意我们&nbsp;<strong>不能&nbsp;</strong>同时选择 <code>"bcdaaaab"</code>,因为它和另一个子字符串有重叠。</p>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= word.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>word</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