Skip to content
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 @@ -32,7 +32,7 @@ tags:
<pre>
<strong>Input:</strong> strs = [&quot;ca&quot;,&quot;bb&quot;,&quot;ac&quot;]
<strong>Output:</strong> 1
<strong>Explanation:</strong>
<strong>Explanation:</strong>
After deleting the first column, strs = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;].
Now strs is in lexicographic order (ie. strs[0] &lt;= strs[1] &lt;= strs[2]).
We require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.
Expand All @@ -43,7 +43,7 @@ We require at least 1 deletion since initially strs was not in lexicographic ord
<pre>
<strong>Input:</strong> strs = [&quot;xc&quot;,&quot;yb&quot;,&quot;za&quot;]
<strong>Output:</strong> 0
<strong>Explanation:</strong>
<strong>Explanation:</strong>
strs is already in lexicographic order, so we do not need to delete anything.
Note that the rows of strs are not necessarily in lexicographic order:
i.e., it is NOT necessarily true that (strs[0][0] &lt;= strs[0][1] &lt;= ...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ tags:

### 方法一:前缀和思想

`[0, x]` 之间的奇数个数为 `(x + 1) >> 1`,那么 `[low, high]` 之间的奇数个数为 `((high + 1) >> 1) - (low >> 1)`。
我们知道,在 $[0, x]$ 范围内奇数的个数为 $\lfloor\frac{x+1}{2}\rfloor$。因此,$[low, high]$ 范围内奇数的个数为 $\lfloor\frac{high+1}{2}\rfloor - \lfloor\frac{low}{2}\rfloor$。

时间复杂度 $O(1)$,空间复杂度 $O(1)$。

<!-- tabs:start -->

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

<!-- solution:start -->

### Solution 1
### Solution 1: Prefix Sum Concept

We know that the count of odd numbers in the range $[0, x]$ is $\lfloor\frac{x+1}{2}\rfloor$. Therefore, the count of odd numbers in the range $[low, high]$ is $\lfloor\frac{high+1}{2}\rfloor - \lfloor\frac{low}{2}\rfloor$.

The time complexity is $O(1)$, and the space complexity is $O(1)$.

<!-- tabs:start -->

Expand Down
2 changes: 1 addition & 1 deletion solution/3700-3799/3764.Most Common Course Pairs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tags:

<pre>
+-------------------+---------+
| Column Name | Type |
| Column Name | Type |
+-------------------+---------+
| user_id | int |
| course_id | int |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tags:

<pre>
+-------------------+---------+
| Column Name | Type |
| Column Name | Type |
+-------------------+---------+
| user_id | int |
| course_id | int |
Expand Down
126 changes: 126 additions & 0 deletions solution/3700-3799/3765.Complete Prime Number/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3700-3799/3765.Complete%20Prime%20Number/README.md
---

<!-- problem:start -->

# [3765. 完全质数](https://leetcode.cn/problems/complete-prime-number)

[English Version](/solution/3700-3799/3765.Complete%20Prime%20Number/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你一个整数 <code>num</code>。</p>

<p>如果一个数 <code>num</code> 的每一个 <strong>前缀</strong> 和每一个 <strong>后缀</strong> 都是 <strong>质数</strong>,则称该数为 <strong>完全质数</strong>。</p>

<p>如果 <code>num</code> 是完全质数,返回 <code>true</code>,否则返回 <code>false</code>。</p>

<p><strong>注意</strong>:</p>

<ul>
<li>一个数的 <strong>前缀</strong> 是由该数的 <strong>前</strong> <code>k</code> 位数字构成的。</li>
<li>一个数的 <strong>后缀</strong> 是由该数的 <strong>后</strong> <code>k</code> 位数字构成的。</li>
<li><strong>质数</strong> 是大于 1 且只有两个因子(1 和它本身)的自然数。</li>
<li>个位数只有在它是 <strong>质数</strong> 时才被视为完全质数。</li>
</ul>

<p>&nbsp;</p>

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

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

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

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

<ul>
<li><code>num = 23</code> 的前缀是 2 和 23,它们都是质数。</li>
<li><code>num = 23</code> 的后缀是 3 和 23,它们都是质数。</li>
<li>所有的前缀和后缀都是质数,所以 23 是完全质数,答案是 <code>true</code>。</li>
</ul>
</div>

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

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

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

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

<ul>
<li><code>num = 39</code> 的前缀是 3 和 39。3 是质数,但 39 不是质数。</li>
<li><code>num = 39</code> 的后缀是 9 和 39。9 和 39 都不是质数。</li>
<li>至少有一个前缀或后缀不是质数,所以 39 不是完全质数,答案是 <code>false</code>。</li>
</ul>
</div>

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

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

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

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

<ul>
<li>7 是质数,所以它的所有前缀和后缀都是质数,答案是 <code>true</code>。</li>
</ul>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
124 changes: 124 additions & 0 deletions solution/3700-3799/3765.Complete Prime Number/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3700-3799/3765.Complete%20Prime%20Number/README_EN.md
---

<!-- problem:start -->

# [3765. Complete Prime Number](https://leetcode.com/problems/complete-prime-number)

[中文文档](/solution/3700-3799/3765.Complete%20Prime%20Number/README.md)

## Description

<!-- description:start -->

<p>You are given an integer <code>num</code>.</p>

<p>A number <code>num</code> is called a <strong>Complete Prime Number</strong> if every <strong>prefix</strong> and every <strong>suffix</strong> of <code>num</code> is <strong>prime</strong>.</p>

<p>Return <code>true</code> if <code>num</code> is a Complete Prime Number, otherwise return <code>false</code>.</p>

<p><strong>Note</strong>:</p>

<ul>
<li>A <strong>prefix</strong> of a number is formed by the <strong>first</strong> <code>k</code> digits of the number.</li>
<li>A <strong>suffix</strong> of a number is formed by the <strong>last</strong> <code>k</code> digits of the number.</li>
<li>A <strong>prime</strong> number is a natural number greater than 1 with only two factors, 1 and itself.</li>
<li>Single-digit numbers are considered Complete Prime Numbers only if they are <strong>prime</strong>.</li>
</ul>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">num = 23</span></p>

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

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

<ul>
<li><strong>​​​​​​​</strong>Prefixes of <code>num = 23</code> are 2 and 23, both are prime.</li>
<li>Suffixes of <code>num = 23</code> are 3 and 23, both are prime.</li>
<li>All prefixes and suffixes are prime, so 23 is a Complete Prime Number and the answer 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">num = 39</span></p>

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

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

<ul>
<li>Prefixes of <code>num = 39</code> are 3 and 39. 3 is prime, but 39 is not prime.</li>
<li>Suffixes of <code>num = 39</code> are 9 and 39. Both 9 and 39 are not prime.</li>
<li>At least one prefix or suffix is not prime, so 39 is not a Complete Prime Number and the answer is <code>false</code>.</li>
</ul>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">num = 7</span></p>

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

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

<ul>
<li>7 is prime, so all its prefixes and suffixes are prime and the answer is <code>true</code>.</li>
</ul>
</div>

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

<ul>
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></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 -->
Loading