Skip to content

Commit 6b05a90

Browse files
committed
feat: add new lc problems
1 parent d6b7f30 commit 6b05a90

File tree

27 files changed

+1548
-3
lines changed

27 files changed

+1548
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# [2268. Minimum Number of Keypresses](https://leetcode.cn/problems/minimum-number-of-keypresses)
2+
3+
[English Version](/solution/2200-2299/2268.Minimum%20Number%20of%20Keypresses/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You have a keypad with <code>9</code> buttons, numbered from <code>1</code> to <code>9</code>, each mapped to lowercase English letters. You can choose which characters each button is matched to as long as:</p>
10+
11+
<ul>
12+
<li>All 26 lowercase English letters are mapped to.</li>
13+
<li>Each character is mapped to by <strong>exactly</strong> <code>1</code> button.</li>
14+
<li>Each button maps to <strong>at most</strong> <code>3</code> characters.</li>
15+
</ul>
16+
17+
<p>To type the first character matched to a button, you press the button once. To type the second character, you press the button twice, and so on.</p>
18+
19+
<p>Given a string <code>s</code>, return <em>the <strong>minimum</strong> number of keypresses needed to type </em><code>s</code><em> using your keypad.</em></p>
20+
21+
<p><strong>Note</strong> that the characters mapped to by each button, and the order they are mapped in cannot be changed.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2268.Minimum%20Number%20of%20Keypresses/images/image-20220505184346-1.png" style="width: 300px; height: 293px;" />
26+
<pre>
27+
<strong>Input:</strong> s = &quot;apple&quot;
28+
<strong>Output:</strong> 5
29+
<strong>Explanation:</strong> One optimal way to setup your keypad is shown above.
30+
Type &#39;a&#39; by pressing button 1 once.
31+
Type &#39;p&#39; by pressing button 6 once.
32+
Type &#39;p&#39; by pressing button 6 once.
33+
Type &#39;l&#39; by pressing button 5 once.
34+
Type &#39;e&#39; by pressing button 3 once.
35+
A total of 5 button presses are needed, so return 5.
36+
</pre>
37+
38+
<p><strong>Example 2:</strong></p>
39+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2268.Minimum%20Number%20of%20Keypresses/images/image-20220505203823-1.png" style="width: 300px; height: 288px;" />
40+
<pre>
41+
<strong>Input:</strong> s = &quot;abcdefghijkl&quot;
42+
<strong>Output:</strong> 15
43+
<strong>Explanation:</strong> One optimal way to setup your keypad is shown above.
44+
The letters &#39;a&#39; to &#39;i&#39; can each be typed by pressing a button once.
45+
Type &#39;j&#39; by pressing button 1 twice.
46+
Type &#39;k&#39; by pressing button 2 twice.
47+
Type &#39;l&#39; by pressing button 3 twice.
48+
A total of 15 button presses are needed, so return 15.
49+
</pre>
50+
51+
<p>&nbsp;</p>
52+
<p><strong>Constraints:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
56+
<li><code>s</code> consists of lowercase English letters.</li>
57+
</ul>
58+
59+
60+
## 解法
61+
62+
<!-- 这里可写通用的实现逻辑 -->
63+
64+
<!-- tabs:start -->
65+
66+
### **Python3**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
<!-- 这里可写当前语言的特殊实现逻辑 -->
77+
78+
```java
79+
80+
```
81+
82+
### **TypeScript**
83+
84+
```ts
85+
86+
```
87+
88+
### **...**
89+
90+
```
91+
92+
```
93+
94+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [2268. Minimum Number of Keypresses](https://leetcode.com/problems/minimum-number-of-keypresses)
2+
3+
[中文文档](/solution/2200-2299/2268.Minimum%20Number%20of%20Keypresses/README.md)
4+
5+
## Description
6+
7+
<p>You have a keypad with <code>9</code> buttons, numbered from <code>1</code> to <code>9</code>, each mapped to lowercase English letters. You can choose which characters each button is matched to as long as:</p>
8+
9+
<ul>
10+
<li>All 26 lowercase English letters are mapped to.</li>
11+
<li>Each character is mapped to by <strong>exactly</strong> <code>1</code> button.</li>
12+
<li>Each button maps to <strong>at most</strong> <code>3</code> characters.</li>
13+
</ul>
14+
15+
<p>To type the first character matched to a button, you press the button once. To type the second character, you press the button twice, and so on.</p>
16+
17+
<p>Given a string <code>s</code>, return <em>the <strong>minimum</strong> number of keypresses needed to type </em><code>s</code><em> using your keypad.</em></p>
18+
19+
<p><strong>Note</strong> that the characters mapped to by each button, and the order they are mapped in cannot be changed.</p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong>Example 1:</strong></p>
23+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2268.Minimum%20Number%20of%20Keypresses/images/image-20220505184346-1.png" style="width: 300px; height: 293px;" />
24+
<pre>
25+
<strong>Input:</strong> s = &quot;apple&quot;
26+
<strong>Output:</strong> 5
27+
<strong>Explanation:</strong> One optimal way to setup your keypad is shown above.
28+
Type &#39;a&#39; by pressing button 1 once.
29+
Type &#39;p&#39; by pressing button 6 once.
30+
Type &#39;p&#39; by pressing button 6 once.
31+
Type &#39;l&#39; by pressing button 5 once.
32+
Type &#39;e&#39; by pressing button 3 once.
33+
A total of 5 button presses are needed, so return 5.
34+
</pre>
35+
36+
<p><strong>Example 2:</strong></p>
37+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2268.Minimum%20Number%20of%20Keypresses/images/image-20220505203823-1.png" style="width: 300px; height: 288px;" />
38+
<pre>
39+
<strong>Input:</strong> s = &quot;abcdefghijkl&quot;
40+
<strong>Output:</strong> 15
41+
<strong>Explanation:</strong> One optimal way to setup your keypad is shown above.
42+
The letters &#39;a&#39; to &#39;i&#39; can each be typed by pressing a button once.
43+
Type &#39;j&#39; by pressing button 1 twice.
44+
Type &#39;k&#39; by pressing button 2 twice.
45+
Type &#39;l&#39; by pressing button 3 twice.
46+
A total of 15 button presses are needed, so return 15.
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
54+
<li><code>s</code> consists of lowercase English letters.</li>
55+
</ul>
56+
57+
58+
## Solutions
59+
60+
<!-- tabs:start -->
61+
62+
### **Python3**
63+
64+
```python
65+
66+
```
67+
68+
### **Java**
69+
70+
```java
71+
72+
```
73+
74+
### **TypeScript**
75+
76+
```ts
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# [2269. 找到一个数字的 K 美丽值](https://leetcode.cn/problems/find-the-k-beauty-of-a-number)
2+
3+
[English Version](/solution/2200-2299/2269.Find%20the%20K-Beauty%20of%20a%20Number/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>一个整数 <code>num</code>&nbsp;&nbsp;<strong>k&nbsp;</strong>美丽值定义为&nbsp;<code>num</code>&nbsp;中符合以下条件的&nbsp;<strong>子字符串</strong>&nbsp;数目:</p>
10+
11+
<ul>
12+
<li>子字符串长度为&nbsp;<code>k</code>&nbsp;。</li>
13+
<li>子字符串能整除 <code>num</code> 。</li>
14+
</ul>
15+
16+
<p>给你整数&nbsp;<code>num</code> 和&nbsp;<code>k</code>&nbsp;,请你返回<em>&nbsp;</em><code>num</code>&nbsp;的 k 美丽值。</p>
17+
18+
<p>注意:</p>
19+
20+
<ul>
21+
<li>允许有&nbsp;<strong>前缀</strong>&nbsp;<strong>0</strong>&nbsp;。</li>
22+
<li><code>0</code>&nbsp;不能整除任何值。</li>
23+
</ul>
24+
25+
<p>一个 <strong>子字符串</strong>&nbsp;是一个字符串里的连续一段字符序列。</p>
26+
27+
<p>&nbsp;</p>
28+
29+
<p><strong>示例 1:</strong></p>
30+
31+
<pre>
32+
<b>输入:</b>num = 240, k = 2
33+
<b>输出:</b>2
34+
<b>解释:</b>以下是 num 里长度为 k 的子字符串:
35+
- "<em><strong>24</strong></em>0" 中的 "24" :24 能整除 240 。
36+
- "2<em><strong>40</strong></em>" 中的 "40" :40 能整除 240 。
37+
所以,k 美丽值为 2 。
38+
</pre>
39+
40+
<p><strong>示例 2:</strong></p>
41+
42+
<pre>
43+
<b>输入:</b>num = 430043, k = 2
44+
<b>输出:</b>2
45+
<b>解释:</b>以下是 num 里长度为 k 的子字符串:
46+
- "<em><strong>43</strong></em>0043" 中的 "43" :43 能整除 430043 。
47+
- "4<em><strong>30</strong></em>043" 中的 "30" :30 不能整除 430043 。
48+
- "43<em><strong>00</strong></em>43" 中的 "00" :0 不能整除 430043 。
49+
- "430<em><strong>04</strong></em>3" 中的 "04" :4 不能整除 430043 。
50+
- "4300<em><strong>43</strong></em>" 中的 "43" :43 能整除 430043 。
51+
所以,k 美丽值为 2 。
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
56+
<p><strong>提示:</strong></p>
57+
58+
<ul>
59+
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>
60+
<li><code>1 &lt;= k &lt;= num.length</code>&nbsp;(将&nbsp;<code>num</code>&nbsp;视为字符串)</li>
61+
</ul>
62+
63+
## 解法
64+
65+
<!-- 这里可写通用的实现逻辑 -->
66+
67+
<!-- tabs:start -->
68+
69+
### **Python3**
70+
71+
<!-- 这里可写当前语言的特殊实现逻辑 -->
72+
73+
```python
74+
75+
```
76+
77+
### **Java**
78+
79+
<!-- 这里可写当前语言的特殊实现逻辑 -->
80+
81+
```java
82+
83+
```
84+
85+
### **TypeScript**
86+
87+
```ts
88+
89+
```
90+
91+
### **...**
92+
93+
```
94+
95+
```
96+
97+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# [2269. Find the K-Beauty of a Number](https://leetcode.com/problems/find-the-k-beauty-of-a-number)
2+
3+
[中文文档](/solution/2200-2299/2269.Find%20the%20K-Beauty%20of%20a%20Number/README.md)
4+
5+
## Description
6+
7+
<p>The <strong>k-beauty</strong> of an integer <code>num</code> is defined as the number of <strong>substrings</strong> of <code>num</code> when it is read as a string that meet the following conditions:</p>
8+
9+
<ul>
10+
<li>It has a length of <code>k</code>.</li>
11+
<li>It is a divisor of <code>num</code>.</li>
12+
</ul>
13+
14+
<p>Given integers <code>num</code> and <code>k</code>, return <em>the k-beauty of </em><code>num</code>.</p>
15+
16+
<p>Note:</p>
17+
18+
<ul>
19+
<li><strong>Leading zeros</strong> are allowed.</li>
20+
<li><code>0</code> is not a divisor of any value.</li>
21+
</ul>
22+
23+
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> num = 240, k = 2
30+
<strong>Output:</strong> 2
31+
<strong>Explanation:</strong> The following are the substrings of num of length k:
32+
- &quot;24&quot; from &quot;<strong><u>24</u></strong>0&quot;: 24 is a divisor of 240.
33+
- &quot;40&quot; from &quot;2<u><strong>40</strong></u>&quot;: 40 is a divisor of 240.
34+
Therefore, the k-beauty is 2.
35+
</pre>
36+
37+
<p><strong>Example 2:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> num = 430043, k = 2
41+
<strong>Output:</strong> 2
42+
<strong>Explanation:</strong> The following are the substrings of num of length k:
43+
- &quot;43&quot; from &quot;<u><strong>43</strong></u>0043&quot;: 43 is a divisor of 430043.
44+
- &quot;30&quot; from &quot;4<u><strong>30</strong></u>043&quot;: 30 is not a divisor of 430043.
45+
- &quot;00&quot; from &quot;43<u><strong>00</strong></u>43&quot;: 0 is not a divisor of 430043.
46+
- &quot;04&quot; from &quot;430<u><strong>04</strong></u>3&quot;: 4 is not a divisor of 430043.
47+
- &quot;43&quot; from &quot;4300<u><strong>43</strong></u>&quot;: 43 is a divisor of 430043.
48+
Therefore, the k-beauty is 2.
49+
</pre>
50+
51+
<p>&nbsp;</p>
52+
<p><strong>Constraints:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>
56+
<li><code>1 &lt;= k &lt;= num.length</code> (taking <code>num</code> as a string)</li>
57+
</ul>
58+
59+
## Solutions
60+
61+
<!-- tabs:start -->
62+
63+
### **Python3**
64+
65+
```python
66+
67+
```
68+
69+
### **Java**
70+
71+
```java
72+
73+
```
74+
75+
### **TypeScript**
76+
77+
```ts
78+
79+
```
80+
81+
### **...**
82+
83+
```
84+
85+
```
86+
87+
<!-- tabs:end -->

0 commit comments

Comments
 (0)