Skip to content

Commit 5e2ef70

Browse files
authored
feat: add biweekly contest 171 (#4882)
1 parent b2c7c21 commit 5e2ef70

File tree

19 files changed

+1160
-8
lines changed

19 files changed

+1160
-8
lines changed

solution/0900-0999/0955.Delete Columns to Make Sorted II/README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tags:
3232
<pre>
3333
<strong>Input:</strong> strs = [&quot;ca&quot;,&quot;bb&quot;,&quot;ac&quot;]
3434
<strong>Output:</strong> 1
35-
<strong>Explanation:</strong>
35+
<strong>Explanation:</strong>
3636
After deleting the first column, strs = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;].
3737
Now strs is in lexicographic order (ie. strs[0] &lt;= strs[1] &lt;= strs[2]).
3838
We require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.
@@ -43,7 +43,7 @@ We require at least 1 deletion since initially strs was not in lexicographic ord
4343
<pre>
4444
<strong>Input:</strong> strs = [&quot;xc&quot;,&quot;yb&quot;,&quot;za&quot;]
4545
<strong>Output:</strong> 0
46-
<strong>Explanation:</strong>
46+
<strong>Explanation:</strong>
4747
strs is already in lexicographic order, so we do not need to delete anything.
4848
Note that the rows of strs are not necessarily in lexicographic order:
4949
i.e., it is NOT necessarily true that (strs[0][0] &lt;= strs[0][1] &lt;= ...)

solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ tags:
5050

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

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

5557
<!-- tabs:start -->
5658

solution/1500-1599/1523.Count Odd Numbers in an Interval Range/README_EN.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ tags:
5858

5959
<!-- solution:start -->
6060

61-
### Solution 1
61+
### Solution 1: Prefix Sum Concept
62+
63+
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$.
64+
65+
The time complexity is $O(1)$, and the space complexity is $O(1)$.
6266

6367
<!-- tabs:start -->
6468

solution/3700-3799/3764.Most Common Course Pairs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tags:
2020

2121
<pre>
2222
+-------------------+---------+
23-
| Column Name | Type |
23+
| Column Name | Type |
2424
+-------------------+---------+
2525
| user_id | int |
2626
| course_id | int |

solution/3700-3799/3764.Most Common Course Pairs/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tags:
2020

2121
<pre>
2222
+-------------------+---------+
23-
| Column Name | Type |
23+
| Column Name | Type |
2424
+-------------------+---------+
2525
| user_id | int |
2626
| course_id | int |
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3700-3799/3765.Complete%20Prime%20Number/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3765. 完全质数](https://leetcode.cn/problems/complete-prime-number)
10+
11+
[English Version](/solution/3700-3799/3765.Complete%20Prime%20Number/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个整数 <code>num</code>。</p>
18+
19+
<p>如果一个数 <code>num</code> 的每一个 <strong>前缀</strong> 和每一个 <strong>后缀</strong> 都是 <strong>质数</strong>,则称该数为 <strong>完全质数</strong>。</p>
20+
21+
<p>如果 <code>num</code> 是完全质数,返回 <code>true</code>,否则返回 <code>false</code>。</p>
22+
23+
<p><strong>注意</strong>:</p>
24+
25+
<ul>
26+
<li>一个数的 <strong>前缀</strong> 是由该数的 <strong>前</strong> <code>k</code> 位数字构成的。</li>
27+
<li>一个数的 <strong>后缀</strong> 是由该数的 <strong>后</strong> <code>k</code> 位数字构成的。</li>
28+
<li><strong>质数</strong> 是大于 1 且只有两个因子(1 和它本身)的自然数。</li>
29+
<li>个位数只有在它是 <strong>质数</strong> 时才被视为完全质数。</li>
30+
</ul>
31+
32+
<p>&nbsp;</p>
33+
34+
<p><strong class="example">示例 1:</strong></p>
35+
36+
<div class="example-block">
37+
<p><strong>输入:</strong><span class="example-io">num = 23</span></p>
38+
39+
<p><strong>输出:</strong><span class="example-io">true</span></p>
40+
41+
<p><strong>解释:</strong></p>
42+
43+
<ul>
44+
<li><code>num = 23</code> 的前缀是 2 和 23,它们都是质数。</li>
45+
<li><code>num = 23</code> 的后缀是 3 和 23,它们都是质数。</li>
46+
<li>所有的前缀和后缀都是质数,所以 23 是完全质数,答案是 <code>true</code>。</li>
47+
</ul>
48+
</div>
49+
50+
<p><strong class="example">示例 2:</strong></p>
51+
52+
<div class="example-block">
53+
<p><strong>输入:</strong><span class="example-io">num = 39</span></p>
54+
55+
<p><strong>输出:</strong><span class="example-io">false</span></p>
56+
57+
<p><strong>解释:</strong></p>
58+
59+
<ul>
60+
<li><code>num = 39</code> 的前缀是 3 和 39。3 是质数,但 39 不是质数。</li>
61+
<li><code>num = 39</code> 的后缀是 9 和 39。9 和 39 都不是质数。</li>
62+
<li>至少有一个前缀或后缀不是质数,所以 39 不是完全质数,答案是 <code>false</code>。</li>
63+
</ul>
64+
</div>
65+
66+
<p><strong class="example">示例 3:</strong></p>
67+
68+
<div class="example-block">
69+
<p><strong>输入:</strong><span class="example-io">num = 7</span></p>
70+
71+
<p><strong>输出:</strong><span class="example-io">true</span></p>
72+
73+
<p><strong>解释:</strong></p>
74+
75+
<ul>
76+
<li>7 是质数,所以它的所有前缀和后缀都是质数,答案是 <code>true</code>。</li>
77+
</ul>
78+
</div>
79+
80+
<p>&nbsp;</p>
81+
82+
<p><strong>提示:</strong></p>
83+
84+
<ul>
85+
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>
86+
</ul>
87+
88+
<!-- description:end -->
89+
90+
## 解法
91+
92+
<!-- solution:start -->
93+
94+
### 方法一
95+
96+
<!-- tabs:start -->
97+
98+
#### Python3
99+
100+
```python
101+
102+
```
103+
104+
#### Java
105+
106+
```java
107+
108+
```
109+
110+
#### C++
111+
112+
```cpp
113+
114+
```
115+
116+
#### Go
117+
118+
```go
119+
120+
```
121+
122+
<!-- tabs:end -->
123+
124+
<!-- solution:end -->
125+
126+
<!-- problem:end -->
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
comments: true
3+
difficulty: Medium
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3700-3799/3765.Complete%20Prime%20Number/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3765. Complete Prime Number](https://leetcode.com/problems/complete-prime-number)
10+
11+
[中文文档](/solution/3700-3799/3765.Complete%20Prime%20Number/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an integer <code>num</code>.</p>
18+
19+
<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>
20+
21+
<p>Return <code>true</code> if <code>num</code> is a Complete Prime Number, otherwise return <code>false</code>.</p>
22+
23+
<p><strong>Note</strong>:</p>
24+
25+
<ul>
26+
<li>A <strong>prefix</strong> of a number is formed by the <strong>first</strong> <code>k</code> digits of the number.</li>
27+
<li>A <strong>suffix</strong> of a number is formed by the <strong>last</strong> <code>k</code> digits of the number.</li>
28+
<li>A <strong>prime</strong> number is a natural number greater than 1 with only two factors, 1 and itself.</li>
29+
<li>Single-digit numbers are considered Complete Prime Numbers only if they are <strong>prime</strong>.</li>
30+
</ul>
31+
32+
<p>&nbsp;</p>
33+
<p><strong class="example">Example 1:</strong></p>
34+
35+
<div class="example-block">
36+
<p><strong>Input:</strong> <span class="example-io">num = 23</span></p>
37+
38+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
39+
40+
<p><strong>Explanation:</strong></p>
41+
42+
<ul>
43+
<li><strong>​​​​​​​</strong>Prefixes of <code>num = 23</code> are 2 and 23, both are prime.</li>
44+
<li>Suffixes of <code>num = 23</code> are 3 and 23, both are prime.</li>
45+
<li>All prefixes and suffixes are prime, so 23 is a Complete Prime Number and the answer is <code>true</code>.</li>
46+
</ul>
47+
</div>
48+
49+
<p><strong class="example">Example 2:</strong></p>
50+
51+
<div class="example-block">
52+
<p><strong>Input:</strong> <span class="example-io">num = 39</span></p>
53+
54+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
55+
56+
<p><strong>Explanation:</strong></p>
57+
58+
<ul>
59+
<li>Prefixes of <code>num = 39</code> are 3 and 39. 3 is prime, but 39 is not prime.</li>
60+
<li>Suffixes of <code>num = 39</code> are 9 and 39. Both 9 and 39 are not prime.</li>
61+
<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>
62+
</ul>
63+
</div>
64+
65+
<p><strong class="example">Example 3:</strong></p>
66+
67+
<div class="example-block">
68+
<p><strong>Input:</strong> <span class="example-io">num = 7</span></p>
69+
70+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
71+
72+
<p><strong>Explanation:</strong></p>
73+
74+
<ul>
75+
<li>7 is prime, so all its prefixes and suffixes are prime and the answer is <code>true</code>.</li>
76+
</ul>
77+
</div>
78+
79+
<p>&nbsp;</p>
80+
<p><strong>Constraints:</strong></p>
81+
82+
<ul>
83+
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>
84+
</ul>
85+
86+
<!-- description:end -->
87+
88+
## Solutions
89+
90+
<!-- solution:start -->
91+
92+
### Solution 1
93+
94+
<!-- tabs:start -->
95+
96+
#### Python3
97+
98+
```python
99+
100+
```
101+
102+
#### Java
103+
104+
```java
105+
106+
```
107+
108+
#### C++
109+
110+
```cpp
111+
112+
```
113+
114+
#### Go
115+
116+
```go
117+
118+
```
119+
120+
<!-- tabs:end -->
121+
122+
<!-- solution:end -->
123+
124+
<!-- problem:end -->

0 commit comments

Comments
 (0)