Skip to content

Commit bce93a0

Browse files
committed
feat: add new leetcode problems
1 parent 46a33cb commit bce93a0

File tree

24 files changed

+961
-6
lines changed

24 files changed

+961
-6
lines changed

images/contributors.svg

+1-1
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [1836. ](https://leetcode-cn.com/problems/remove-duplicates-from-an-unsorted-linked-list)
2+
3+
[English Version](/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/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,86 @@
1+
# [1836. Remove Duplicates From an Unsorted Linked List](https://leetcode.com/problems/remove-duplicates-from-an-unsorted-linked-list)
2+
3+
[中文文档](/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README.md)
4+
5+
## Description
6+
7+
<p>Given the <code>head</code> of a linked list, find all the values that appear <strong>more than once</strong> in the list and delete the nodes that have any of those values.</p>
8+
9+
<p>Return <em>the linked list after the deletions.</em></p>
10+
11+
<p>&nbsp;</p>
12+
13+
<p><strong>Example 1:</strong></p>
14+
15+
<img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/images/tmp-linked-list.jpg" style="width: 422px; height: 222px;" />
16+
17+
<pre>
18+
19+
<strong>Input:</strong> head = [1,2,3,2]
20+
21+
<strong>Output:</strong> [1,3]
22+
23+
<strong>Explanation:</strong> 2 appears twice in the linked list, so all 2&#39;s should be deleted. After deleting all 2&#39;s, we are left with [1,3].
24+
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/images/tmp-linked-list-1.jpg" style="width: 422px; height: 151px;" />
30+
31+
<pre>
32+
33+
<strong>Input:</strong> head = [2,1,1,2]
34+
35+
<strong>Output:</strong> []
36+
37+
<strong>Explanation:</strong> 2 and 1 both appear twice. All the elements should be deleted.
38+
39+
</pre>
40+
41+
<p><strong>Example 3:</strong></p>
42+
43+
<img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/images/tmp-linked-list-2.jpg" style="width: 500px; height: 142px;" />
44+
45+
<pre>
46+
47+
<strong>Input:</strong> head = [3,2,2,1,3,2,4]
48+
49+
<strong>Output:</strong> [1,4]
50+
51+
<strong>Explanation: </strong>3 appears twice and 2 appears three times. After deleting all 3&#39;s and 2&#39;s, we are left with [1,4].
52+
53+
</pre>
54+
55+
<p>&nbsp;</p>
56+
57+
<p><strong>Constraints:</strong></p>
58+
59+
<ul>
60+
<li>The number of nodes in the list is in the range&nbsp;<code>[1, 10<sup>5</sup>]</code></li>
61+
<li><code>1 &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
62+
</ul>
63+
64+
## Solutions
65+
66+
<!-- tabs:start -->
67+
68+
### **Python3**
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
```java
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# [1837. K 进制表示下的各位数字总和](https://leetcode-cn.com/problems/sum-of-digits-in-base-k)
2+
3+
[English Version](/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个整数 <code>n</code>(<code>10</code> 进制)和一个基数 <code>k</code> ,请你将 <code>n</code> 从 <code>10</code> 进制表示转换为 <code>k</code> 进制表示,计算并返回转换后各位数字的 <strong>总和</strong> 。</p>
10+
11+
<p>转换后,各位数字应当视作是 <code>10</code> 进制数字,且它们的总和也应当按 <code>10</code> 进制表示返回。</p>
12+
13+
<p> </p>
14+
15+
<p><strong>示例 1:</strong></p>
16+
17+
<pre>
18+
<strong>输入:</strong>n = 34, k = 6
19+
<strong>输出:</strong>9
20+
<strong>解释:</strong>34 (10 进制) 在 6 进制下表示为 54 。5 + 4 = 9 。
21+
</pre>
22+
23+
<p><strong>示例 2:</strong></p>
24+
25+
<pre>
26+
<strong>输入:</strong>n = 10, k = 10
27+
<strong>输出:</strong>1
28+
<strong>解释:</strong>n 本身就是 10 进制。 1 + 0 = 1 。
29+
</pre>
30+
31+
<p> </p>
32+
33+
<p><strong>提示:</strong></p>
34+
35+
<ul>
36+
<li><code>1 <= n <= 100</code></li>
37+
<li><code>2 <= k <= 10</code></li>
38+
</ul>
39+
40+
41+
## 解法
42+
43+
<!-- 这里可写通用的实现逻辑 -->
44+
45+
<!-- tabs:start -->
46+
47+
### **Python3**
48+
49+
<!-- 这里可写当前语言的特殊实现逻辑 -->
50+
51+
```python
52+
53+
```
54+
55+
### **Java**
56+
57+
<!-- 这里可写当前语言的特殊实现逻辑 -->
58+
59+
```java
60+
61+
```
62+
63+
### **...**
64+
65+
```
66+
67+
```
68+
69+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# [1837. Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k)
2+
3+
[中文文档](/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README.md)
4+
5+
## Description
6+
7+
<p>Given an integer <code>n</code> (in base <code>10</code>) and a base <code>k</code>, return <em>the <strong>sum</strong> of the digits of </em><code>n</code><em> <strong>after</strong> converting </em><code>n</code><em> from base </em><code>10</code><em> to base </em><code>k</code>.</p>
8+
9+
<p>After converting, each digit should be interpreted as a base <code>10</code> number, and the sum should be returned in base <code>10</code>.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong>Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> n = 34, k = 6
16+
<strong>Output:</strong> 9
17+
<strong>Explanation: </strong>34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> n = 10, k = 10
24+
<strong>Output:</strong> 1
25+
<strong>Explanation: </strong>n is already in base 10. 1 + 0 = 1.
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>1 &lt;= n &lt;= 100</code></li>
33+
<li><code>2 &lt;= k &lt;= 10</code></li>
34+
</ul>
35+
36+
37+
## Solutions
38+
39+
<!-- tabs:start -->
40+
41+
### **Python3**
42+
43+
```python
44+
45+
```
46+
47+
### **Java**
48+
49+
```java
50+
51+
```
52+
53+
### **...**
54+
55+
```
56+
57+
```
58+
59+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [1838. 最高频元素的频数](https://leetcode-cn.com/problems/frequency-of-the-most-frequent-element)
2+
3+
[English Version](/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>元素的 <strong>频数</strong> 是该元素在一个数组中出现的次数。</p>
10+
11+
<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>k</code> 。在一步操作中,你可以选择 <code>nums</code> 的一个下标,并将该下标对应元素的值增加 <code>1</code> 。</p>
12+
13+
<p>执行最多 <code>k</code> 次操作后,返回数组中最高频元素的 <strong>最大可能频数</strong> <em>。</em></p>
14+
15+
<p> </p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre>
20+
<strong>输入:</strong>nums = [1,2,4], k = 5
21+
<strong>输出:</strong>3<strong>
22+
解释:</strong>对第一个元素执行 3 次递增操作,对第二个元素执 2 次递增操作,此时 nums = [4,4,4] 。
23+
4 是数组中最高频元素,频数是 3 。</pre>
24+
25+
<p><strong>示例 2:</strong></p>
26+
27+
<pre>
28+
<strong>输入:</strong>nums = [1,4,8,13], k = 5
29+
<strong>输出:</strong>2
30+
<strong>解释:</strong>存在多种最优解决方案:
31+
- 对第一个元素执行 3 次递增操作,此时 nums = [4,4,8,13] 。4 是数组中最高频元素,频数是 2 。
32+
- 对第二个元素执行 4 次递增操作,此时 nums = [1,8,8,13] 。8 是数组中最高频元素,频数是 2 。
33+
- 对第三个元素执行 5 次递增操作,此时 nums = [1,4,13,13] 。13 是数组中最高频元素,频数是 2 。
34+
</pre>
35+
36+
<p><strong>示例 3:</strong></p>
37+
38+
<pre>
39+
<strong>输入:</strong>nums = [3,9,6], k = 2
40+
<strong>输出:</strong>1
41+
</pre>
42+
43+
<p> </p>
44+
45+
<p><strong>提示:</strong></p>
46+
47+
<ul>
48+
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
49+
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
50+
<li><code>1 <= k <= 10<sup>5</sup></code></li>
51+
</ul>
52+
53+
54+
## 解法
55+
56+
<!-- 这里可写通用的实现逻辑 -->
57+
58+
<!-- tabs:start -->
59+
60+
### **Python3**
61+
62+
<!-- 这里可写当前语言的特殊实现逻辑 -->
63+
64+
```python
65+
66+
```
67+
68+
### **Java**
69+
70+
<!-- 这里可写当前语言的特殊实现逻辑 -->
71+
72+
```java
73+
74+
```
75+
76+
### **...**
77+
78+
```
79+
80+
```
81+
82+
<!-- tabs:end -->

0 commit comments

Comments
 (0)