Skip to content

Commit 415730e

Browse files
committed
feat: add new leetcode problems
1 parent 3e7dfab commit 415730e

File tree

29 files changed

+1752
-9
lines changed

29 files changed

+1752
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [1842. ](https://leetcode-cn.com/problems/next-palindrome-using-same-digits)
2+
3+
[English Version](/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **Python3**
18+
19+
<!-- 这里可写当前语言的特殊实现逻辑 -->
20+
21+
```python
22+
23+
```
24+
25+
### **Java**
26+
27+
<!-- 这里可写当前语言的特殊实现逻辑 -->
28+
29+
```java
30+
31+
```
32+
33+
### **...**
34+
35+
```
36+
37+
```
38+
39+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [1842. Next Palindrome Using Same Digits](https://leetcode.com/problems/next-palindrome-using-same-digits)
2+
3+
[中文文档](/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README.md)
4+
5+
## Description
6+
7+
<p>You are given a numeric string <code>num</code>, representing a very large <strong>palindrome</strong>.</p>
8+
9+
<p>Return<em> the <strong>smallest palindrome larger than </strong></em><code>num</code><em> that can be created by rearranging its digits. If no such palindrome exists, return an empty string </em><code>&quot;&quot;</code>.</p>
10+
11+
<p>A <strong>palindrome</strong> is a number that reads the same backward as forward.</p>
12+
13+
<p>&nbsp;</p>
14+
15+
<p><strong>Example 1:</strong></p>
16+
17+
<pre>
18+
19+
<strong>Input:</strong> num = &quot;1221&quot;
20+
21+
<strong>Output:</strong> &quot;2112&quot;
22+
23+
<strong>Explanation:</strong>&nbsp;The next palindrome larger than &quot;1221&quot; is &quot;2112&quot;.
24+
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
31+
<strong>Input:</strong> num = &quot;32123&quot;
32+
33+
<strong>Output:</strong> &quot;&quot;
34+
35+
<strong>Explanation:</strong>&nbsp;No palindromes larger than &quot;32123&quot; can be made by rearranging the digits.
36+
37+
</pre>
38+
39+
<p><strong>Example 3:</strong></p>
40+
41+
<pre>
42+
43+
<strong>Input:</strong> num = &quot;45544554&quot;
44+
45+
<strong>Output:</strong> &quot;54455445&quot;
46+
47+
<strong>Explanation:</strong> The next palindrome larger than &quot;45544554&quot; is &quot;54455445&quot;.
48+
49+
</pre>
50+
51+
<p>&nbsp;</p>
52+
53+
<p><strong>Constraints:</strong></p>
54+
55+
<ul>
56+
<li><code>1 &lt;= num.length &lt;= 10<sup>5</sup></code></li>
57+
<li><code>num</code> is a <strong>palindrome</strong>.</li>
58+
</ul>
59+
60+
## Solutions
61+
62+
<!-- tabs:start -->
63+
64+
### **Python3**
65+
66+
```python
67+
68+
```
69+
70+
### **Java**
71+
72+
```java
73+
74+
```
75+
76+
### **...**
77+
78+
```
79+
80+
```
81+
82+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [1843. ](https://leetcode-cn.com/problems/suspicious-bank-accounts)
2+
3+
[English Version](/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **Python3**
18+
19+
<!-- 这里可写当前语言的特殊实现逻辑 -->
20+
21+
```python
22+
23+
```
24+
25+
### **Java**
26+
27+
<!-- 这里可写当前语言的特殊实现逻辑 -->
28+
29+
```java
30+
31+
```
32+
33+
### **...**
34+
35+
```
36+
37+
```
38+
39+
<!-- tabs:end -->

solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# [1843. Suspicious Bank Accounts](https://leetcode.com/problems/suspicious-bank-accounts)
2+
3+
[中文文档](/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Accounts</code></p>
8+
9+
<pre>
10+
+----------------+------+
11+
| Column Name | Type |
12+
+----------------+------+
13+
| account_id | int |
14+
| max_income | int |
15+
+----------------+------+
16+
account_id is the primary key for this table.
17+
Each row contains information about the maximum monthly income for one bank account.
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
22+
<p>Table: <code>Transactions</code></p>
23+
24+
<pre>
25+
+----------------+----------+
26+
| Column Name | Type |
27+
+----------------+----------+
28+
| transaction_id | int |
29+
| account_id | int |
30+
| type | ENUM |
31+
| amount | int |
32+
| day | datetime |
33+
+----------------+----------+
34+
transaction_id is the primary key for this table.
35+
Each row contains information about one transaction.
36+
type is ENUM (&#39;Creditor&#39;,&#39;Debtor&#39;) where &#39;Creditor&#39; means the user deposited money into their account and &#39;Debtor&#39; means the user withdrew money from their account.
37+
amount is the amount of money depositied/withdrawn during the transaction.
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
42+
<p>Write an SQL query to report the IDs of all&nbsp;<strong>suspicious</strong> bank accounts.</p>
43+
44+
<p>A bank account is <strong>suspicious</strong> if the <strong>total income</strong> exceeds the <code>max_income</code> for this account for <strong>two or more consecutive</strong> months. The <strong>total income</strong> of an account in some month is the sum of all its deposits in that month (i.e., transactions of the type <code>&#39;Creditor&#39;</code>).</p>
45+
46+
<p>Return the result table <strong>in ascending order by </strong><code>transaction_id</code>.</p>
47+
48+
<p>The query result format is in the following example:</p>
49+
50+
<p>&nbsp;</p>
51+
52+
<pre>
53+
Accounts table:
54+
+------------+------------+
55+
| account_id | max_income |
56+
+------------+------------+
57+
| 3 | 21000 |
58+
| 4 | 10400 |
59+
+------------+------------+
60+
61+
Transactions table:
62+
+----------------+------------+----------+--------+---------------------+
63+
| transaction_id | account_id | type | amount | day |
64+
+----------------+------------+----------+--------+---------------------+
65+
| 2 | 3 | Creditor | 107100 | 2021-06-02 11:38:14 |
66+
| 4 | 4 | Creditor | 10400 | 2021-06-20 12:39:18 |
67+
| 11 | 4 | Debtor | 58800 | 2021-07-23 12:41:55 |
68+
| 1 | 4 | Creditor | 49300 | 2021-05-03 16:11:04 |
69+
| 15 | 3 | Debtor | 75500 | 2021-05-23 14:40:20 |
70+
| 10 | 3 | Creditor | 102100 | 2021-06-15 10:37:16 |
71+
| 14 | 4 | Creditor | 56300 | 2021-07-21 12:12:25 |
72+
| 19 | 4 | Debtor | 101100 | 2021-05-09 15:21:49 |
73+
| 8 | 3 | Creditor | 64900 | 2021-07-26 15:09:56 |
74+
| 7 | 3 | Creditor | 90900 | 2021-06-14 11:23:07 |
75+
+----------------+------------+----------+--------+---------------------+
76+
77+
Result table:
78+
+------------+
79+
| account_id |
80+
+------------+
81+
| 3 |
82+
+------------+
83+
84+
For account 3:
85+
- In 6-2021, the user had an income of 107100 + 102100 + 90900 = 300100.
86+
- In 7-2021, the user had an income of 64900.
87+
We can see that the income exceeded the max income of 21000 for two consecutive months, so we include 3 in the result table.
88+
89+
For account 4:
90+
- In 5-2021, the user had an income of 49300.
91+
- In 6-2021, the user had an income of 10400.
92+
- In 7-2021, the user had an income of 56300.
93+
We can see that the income exceeded the max income in May and July, but not in June. Since the account did not exceed the max income for two consecutive months, we do not include it in the result table.
94+
</pre>
95+
96+
## Solutions
97+
98+
<!-- tabs:start -->
99+
100+
### **Python3**
101+
102+
```python
103+
104+
```
105+
106+
### **Java**
107+
108+
```java
109+
110+
```
111+
112+
### **...**
113+
114+
```
115+
116+
```
117+
118+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# [1844. 将所有数字用字符替换](https://leetcode-cn.com/problems/replace-all-digits-with-characters)
2+
3+
[English Version](/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>s</code> ,它的 <strong>偶数</strong> 下标处为小写英文字母,<strong>奇数</strong> 下标处为数字。</p>
10+
11+
<p>定义一个函数 <code>shift(c, x)</code> ,其中 <code>c</code> 是一个字符且 <code>x</code> 是一个数字,函数返回字母表中 <code>c</code> 后面第 <code>x</code> 个字符。</p>
12+
13+
<ul>
14+
<li>比方说,<code>shift('a', 5) = 'f'</code> 和 <code>shift('x', 0) = 'x'</code> 。</li>
15+
</ul>
16+
17+
<p>对于每个 <strong>奇数</strong> 下标 <code>i</code> ,你需要将数字 <code>s[i]</code> 用 <code>shift(s[i-1], s[i])</code> 替换。</p>
18+
19+
<p>请你替换所有数字以后,将字符串 <code>s</code> 返回。题目 <strong>保证</strong><em> </em><code>shift(s[i-1], s[i])</code> 不会超过 <code>'z'</code> 。</p>
20+
21+
<p> </p>
22+
23+
<p><strong>示例 1:</strong></p>
24+
25+
<pre><b>输入:</b>s = "a1c1e1"
26+
<b>输出:</b>"abcdef"
27+
<strong>解释:</strong>数字被替换结果如下:
28+
- s[1] -&gt; shift('a',1) = 'b'
29+
- s[3] -&gt; shift('c',1) = 'd'
30+
- s[5] -&gt; shift('e',1) = 'f'</pre>
31+
32+
<p><strong>示例 2:</strong></p>
33+
34+
<pre><b>输入:</b>s = "a1b2c3d4e"
35+
<b>输出:</b>"abbdcfdhe"
36+
<strong>解释:</strong>数字被替换结果如下:
37+
- s[1] -&gt; shift('a',1) = 'b'
38+
- s[3] -&gt; shift('b',2) = 'd'
39+
- s[5] -&gt; shift('c',3) = 'f'
40+
- s[7] -&gt; shift('d',4) = 'h'</pre>
41+
42+
<p> </p>
43+
44+
<p><strong>提示:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= s.length &lt;= 100</code></li>
48+
<li><code>s</code> 只包含小写英文字母和数字。</li>
49+
<li>对所有 <strong>奇数</strong> 下标处的 <code>i</code> ,满足 <code>shift(s[i-1], s[i]) &lt;= 'z'</code> 。</li>
50+
</ul>
51+
52+
53+
## 解法
54+
55+
<!-- 这里可写通用的实现逻辑 -->
56+
57+
<!-- tabs:start -->
58+
59+
### **Python3**
60+
61+
<!-- 这里可写当前语言的特殊实现逻辑 -->
62+
63+
```python
64+
65+
```
66+
67+
### **Java**
68+
69+
<!-- 这里可写当前语言的特殊实现逻辑 -->
70+
71+
```java
72+
73+
```
74+
75+
### **...**
76+
77+
```
78+
79+
```
80+
81+
<!-- tabs:end -->

0 commit comments

Comments
 (0)