Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a75c20b

Browse files
committed
feat: add new leetcode problems and solutions
1 parent b9a06c1 commit a75c20b

File tree

40 files changed

+1995
-7
lines changed

40 files changed

+1995
-7
lines changed

‎solution/1700-1799/1773.Count Items Matching a Rule/README.md‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,38 @@
6060
<!-- 这里可写当前语言的特殊实现逻辑 -->
6161

6262
```python
63-
63+
class Solution:
64+
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
65+
count = 0
66+
m = {
67+
'type': 0,
68+
'color': 1,
69+
'name': 2
70+
}
71+
return sum([item[m[ruleKey]] == ruleValue for item in items])
6472
```
6573

6674
### **Java**
6775

6876
<!-- 这里可写当前语言的特殊实现逻辑 -->
6977

7078
```java
71-
79+
class Solution {
80+
public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
81+
int count = 0;
82+
for (List<String> item : items) {
83+
String t = item.get(0), c = item.get(1), n = item.get(2);
84+
if ("type".equals(ruleKey) && t.equals(ruleValue)) {
85+
++count;
86+
} else if ("color".equals(ruleKey) && c.equals(ruleValue)) {
87+
++count;
88+
} else if ("name".equals(ruleKey) && n.equals(ruleValue)) {
89+
++count;
90+
}
91+
}
92+
return count;
93+
}
94+
}
7295
```
7396

7497
### **...**

‎solution/1700-1799/1773.Count Items Matching a Rule/README_EN.md‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,36 @@
5050
### **Python3**
5151

5252
```python
53-
53+
class Solution:
54+
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
55+
count = 0
56+
m = {
57+
'type': 0,
58+
'color': 1,
59+
'name': 2
60+
}
61+
return sum([item[m[ruleKey]] == ruleValue for item in items])
5462
```
5563

5664
### **Java**
5765

5866
```java
59-
67+
class Solution {
68+
public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
69+
int count = 0;
70+
for (List<String> item : items) {
71+
String t = item.get(0), c = item.get(1), n = item.get(2);
72+
if ("type".equals(ruleKey) && t.equals(ruleValue)) {
73+
++count;
74+
} else if ("color".equals(ruleKey) && c.equals(ruleValue)) {
75+
++count;
76+
} else if ("name".equals(ruleKey) && n.equals(ruleValue)) {
77+
++count;
78+
}
79+
}
80+
return count;
81+
}
82+
}
6083
```
6184

6285
### **...**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
3+
int count = 0;
4+
for (List<String> item : items) {
5+
String t = item.get(0), c = item.get(1), n = item.get(2);
6+
if ("type".equals(ruleKey) && t.equals(ruleValue)) {
7+
++count;
8+
} else if ("color".equals(ruleKey) && c.equals(ruleValue)) {
9+
++count;
10+
} else if ("name".equals(ruleKey) && n.equals(ruleValue)) {
11+
++count;
12+
}
13+
}
14+
return count;
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:
3+
count = 0
4+
m = {
5+
'type': 0,
6+
'color': 1,
7+
'name': 2
8+
}
9+
return sum([item[m[ruleKey]] == ruleValue for item in items])
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# [1941. 检查是否所有字符出现次数相同](https://leetcode-cn.com/problems/check-if-all-characters-have-equal-number-of-occurrences)
2+
3+
[English Version](/solution/1900-1999/1941.Check%20if%20All%20Characters%20Have%20Equal%20Number%20of%20Occurrences/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个字符串 <code>s</code> ,如果 <code>s</code> 是一个 <strong>好</strong> 字符串,请你返回 <code>true</code> ,否则请返回 <code>false</code> 。</p>
10+
11+
<p>如果 <code>s</code> 中出现过的 <strong>所有</strong> 字符的出现次数 <strong>相同</strong> ,那么我们称字符串 <code>s</code> 是 <strong>好</strong> 字符串。</p>
12+
13+
<p> </p>
14+
15+
<p><strong>示例 1:</strong></p>
16+
17+
<pre><b>输入:</b>s = "abacbc"
18+
<b>输出:</b>true
19+
<b>解释:</b>s 中出现过的字符为 'a','b' 和 'c' 。s 中所有字符均出现 2 次。
20+
</pre>
21+
22+
<p><strong>示例 2:</strong></p>
23+
24+
<pre><b>输入:</b>s = "aaabb"
25+
<b>输出:</b>false
26+
<b>解释:</b>s 中出现过的字符为 'a' 和 'b' 。
27+
'a' 出现了 3 次,'b' 出现了 2 次,两者出现次数不同。
28+
</pre>
29+
30+
<p> </p>
31+
32+
<p><strong>提示:</strong></p>
33+
34+
<ul>
35+
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
36+
<li><code>s</code> 只包含小写英文字母。</li>
37+
</ul>
38+
39+
40+
## 解法
41+
42+
<!-- 这里可写通用的实现逻辑 -->
43+
44+
<!-- tabs:start -->
45+
46+
### **Python3**
47+
48+
<!-- 这里可写当前语言的特殊实现逻辑 -->
49+
50+
```python
51+
52+
```
53+
54+
### **Java**
55+
56+
<!-- 这里可写当前语言的特殊实现逻辑 -->
57+
58+
```java
59+
60+
```
61+
62+
### **...**
63+
64+
```
65+
66+
```
67+
68+
<!-- tabs:end -->
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# [1941. Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences)
2+
3+
[中文文档](/solution/1900-1999/1941.Check%20if%20All%20Characters%20Have%20Equal%20Number%20of%20Occurrences/README.md)
4+
5+
## Description
6+
7+
<p>Given a string <code>s</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>good</strong> string, or </em><code>false</code><em> otherwise</em>.</p>
8+
9+
<p>A string <code>s</code> is <strong>good</strong> if <strong>all</strong> the characters that appear in <code>s</code> have the <strong>same</strong> number of occurrences (i.e., the same frequency).</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong>Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> s = &quot;abacbc&quot;
16+
<strong>Output:</strong> true
17+
<strong>Explanation:</strong> The characters that appear in s are &#39;a&#39;, &#39;b&#39;, and &#39;c&#39;. All characters occur 2 times in s.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> s = &quot;aaabb&quot;
24+
<strong>Output:</strong> false
25+
<strong>Explanation:</strong> The characters that appear in s are &#39;a&#39; and &#39;b&#39;.
26+
&#39;a&#39; occurs 3 times while &#39;b&#39; occurs 2 times, which is not the same number of times.
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
34+
<li><code>s</code> consists of lowercase English letters.</li>
35+
</ul>
36+
37+
38+
## Solutions
39+
40+
<!-- tabs:start -->
41+
42+
### **Python3**
43+
44+
```python
45+
46+
```
47+
48+
### **Java**
49+
50+
```java
51+
52+
```
53+
54+
### **...**
55+
56+
```
57+
58+
```
59+
60+
<!-- tabs:end -->
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [1942. 最小未被占据椅子的编号](https://leetcode-cn.com/problems/the-number-of-the-smallest-unoccupied-chair)
2+
3+
[English Version](/solution/1900-1999/1942.The%20Number%20of%20the%20Smallest%20Unoccupied%20Chair/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>有 <code>n</code> 个朋友在举办一个派对,这些朋友从 <code>0</code> 到 <code>n - 1</code> 编号。派对里有 <strong>无数</strong> 张椅子,编号为 <code>0</code> 到 <code>infinity</code> 。当一个朋友到达派对时,他会占据 <strong>编号最小</strong> 且未被占据的椅子。</p>
10+
11+
<ul>
12+
<li>比方说,当一个朋友到达时,如果椅子 <code>0</code> ,<code>1</code> 和 <code>5</code> 被占据了,那么他会占据 <code>2</code> 号椅子。</li>
13+
</ul>
14+
15+
<p>当一个朋友离开派对时,他的椅子会立刻变成未占据状态。如果同一时刻有另一个朋友到达,可以立即占据这张椅子。</p>
16+
17+
<p>给你一个下标从 <strong>0</strong> 开始的二维整数数组 <code>times</code> ,其中 <code>times[i] = [arrival<sub>i</sub>, leaving<sub>i</sub>]</code> 表示第 <code>i</code> 个朋友到达和离开的时刻,同时给你一个整数 <code>targetFriend</code> 。所有到达时间 <strong>互不相同</strong> 。</p>
18+
19+
<p>请你返回编号为 <code>targetFriend</code> 的朋友占据的 <strong>椅子编号</strong> 。</p>
20+
21+
<p> </p>
22+
23+
<p><strong>示例 1:</strong></p>
24+
25+
<pre><b>输入:</b>times = [[1,4],[2,3],[4,6]], targetFriend = 1
26+
<b>输出:</b>1
27+
<b>解释:</b>
28+
- 朋友 0 时刻 1 到达,占据椅子 0 。
29+
- 朋友 1 时刻 2 到达,占据椅子 1 。
30+
- 朋友 1 时刻 3 离开,椅子 1 变成未占据。
31+
- 朋友 0 时刻 4 离开,椅子 0 变成未占据。
32+
- 朋友 2 时刻 4 到达,占据椅子 0 。
33+
朋友 1 占据椅子 1 ,所以返回 1 。
34+
</pre>
35+
36+
<p><strong>示例 2:</strong></p>
37+
38+
<pre><b>输入:</b>times = [[3,10],[1,5],[2,6]], targetFriend = 0
39+
<b>输出:</b>2
40+
<b>解释:</b>
41+
- 朋友 1 时刻 1 到达,占据椅子 0 。
42+
- 朋友 2 时刻 2 到达,占据椅子 1 。
43+
- 朋友 0 时刻 3 到达,占据椅子 2 。
44+
- 朋友 1 时刻 5 离开,椅子 0 变成未占据。
45+
- 朋友 2 时刻 6 离开,椅子 1 变成未占据。
46+
- 朋友 0 时刻 10 离开,椅子 2 变成未占据。
47+
朋友 0 占据椅子 2 ,所以返回 2 。
48+
</pre>
49+
50+
<p> </p>
51+
52+
<p><strong>提示:</strong></p>
53+
54+
<ul>
55+
<li><code>n == times.length</code></li>
56+
<li><code>2 &lt;= n &lt;= 10<sup>4</sup></code></li>
57+
<li><code>times[i].length == 2</code></li>
58+
<li><code>1 &lt;= arrival<sub>i</sub> &lt; leaving<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
59+
<li><code>0 &lt;= targetFriend &lt;= n - 1</code></li>
60+
<li>每个 <code>arrival<sub>i</sub></code> 时刻 <strong>互不相同</strong> 。</li>
61+
</ul>
62+
63+
64+
## 解法
65+
66+
<!-- 这里可写通用的实现逻辑 -->
67+
68+
<!-- tabs:start -->
69+
70+
### **Python3**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```python
75+
76+
```
77+
78+
### **Java**
79+
80+
<!-- 这里可写当前语言的特殊实现逻辑 -->
81+
82+
```java
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /