Skip to content

Commit 155e30b

Browse files
committedNov 8, 2021
feat: add new lc problems: No.2061+
1 parent 57e2c78 commit 155e30b

File tree

22 files changed

+1067
-42
lines changed

22 files changed

+1067
-42
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# [2061. Number of Spaces Cleaning Robot Cleaned](https://leetcode-cn.com/problems/number-of-spaces-cleaning-robot-cleaned)
2+
3+
[English Version](/solution/2000-2099/2061.Number%20of%20Spaces%20Cleaning%20Robot%20Cleaned/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>A room is represented by a <strong>0-indexed</strong> 2D binary matrix <code>room</code> where a <code>0</code> represents an <strong>empty</strong> space and a <code>1</code> represents a space with an <strong>object</strong>. The top left corner of the room will be empty in all test cases.</p>
10+
11+
<p>A cleaning robot starts at the top left corner of the room and is facing right. The robot will continue heading straight until it reaches the edge of the room or it hits an object, after which it will turn 90 degrees <strong>clockwise</strong> and repeat this process. The starting space and all spaces that the robot visits are <strong>cleaned</strong> by it.</p>
12+
13+
<p>Return <em>the number of <strong>clean</strong> spaces in the room if the robot runs indefinetely.</em></p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong><br />
17+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2000-2099/2061.Number%20of%20Spaces%20Cleaning%20Robot%20Cleaned/images/image-20211101204703-1.png" style="width: 250px; height: 242px;" /></p>
18+
19+
<pre>
20+
<strong>Input:</strong> room = [[0,0,0],[1,1,0],[0,0,0]]
21+
<strong>Output:</strong> 7
22+
<strong>Explanation:</strong>
23+
The robot cleans the spaces at (0, 0), (0, 1), and (0, 2).
24+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces down.
25+
The robot cleans the spaces at (1, 2), and (2, 2).
26+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces left.
27+
The robot cleans the spaces at (2, 1), and (2, 0).
28+
The robot has cleaned all 7 empty spaces, so return 7.
29+
</pre>
30+
31+
<p><strong>Example 2:</strong><br />
32+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2000-2099/2061.Number%20of%20Spaces%20Cleaning%20Robot%20Cleaned/images/image-20211101204736-2.png" style="width: 250px; height: 245px;" /></p>
33+
34+
<pre>
35+
<strong>Input:</strong> room = [[0,1,0],[1,0,0],[0,0,0]]
36+
<strong>Output:</strong> 1
37+
<strong>Explanation:</strong>
38+
The robot cleans the space at (0, 0).
39+
The robot hits an object, so it turns 90 degrees clockwise and now faces down.
40+
The robot hits an object, so it turns 90 degrees clockwise and now faces left.
41+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces up.
42+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces right.
43+
The robot is back at its starting position.
44+
The robot has cleaned 1 space, so return 1.
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>m == room.length</code></li>
52+
<li><code>n == room[r].length</code></li>
53+
<li><code>1 &lt;= m, n &lt;= 300</code></li>
54+
<li><code>room[r][c]</code> is either <code>0</code> or <code>1</code>.</li>
55+
<li><code>room[0][0] == 0</code></li>
56+
</ul>
57+
58+
59+
## 解法
60+
61+
<!-- 这里可写通用的实现逻辑 -->
62+
63+
<!-- tabs:start -->
64+
65+
### **Python3**
66+
67+
<!-- 这里可写当前语言的特殊实现逻辑 -->
68+
69+
```python
70+
71+
```
72+
73+
### **Java**
74+
75+
<!-- 这里可写当前语言的特殊实现逻辑 -->
76+
77+
```java
78+
79+
```
80+
81+
### **...**
82+
83+
```
84+
85+
```
86+
87+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2061. Number of Spaces Cleaning Robot Cleaned](https://leetcode.com/problems/number-of-spaces-cleaning-robot-cleaned)
2+
3+
[中文文档](/solution/2000-2099/2061.Number%20of%20Spaces%20Cleaning%20Robot%20Cleaned/README.md)
4+
5+
## Description
6+
7+
<p>A room is represented by a <strong>0-indexed</strong> 2D binary matrix <code>room</code> where a <code>0</code> represents an <strong>empty</strong> space and a <code>1</code> represents a space with an <strong>object</strong>. The top left corner of the room will be empty in all test cases.</p>
8+
9+
<p>A cleaning robot starts at the top left corner of the room and is facing right. The robot will continue heading straight until it reaches the edge of the room or it hits an object, after which it will turn 90 degrees <strong>clockwise</strong> and repeat this process. The starting space and all spaces that the robot visits are <strong>cleaned</strong> by it.</p>
10+
11+
<p>Return <em>the number of <strong>clean</strong> spaces in the room if the robot runs indefinetely.</em></p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong><br />
15+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2000-2099/2061.Number%20of%20Spaces%20Cleaning%20Robot%20Cleaned/images/image-20211101204703-1.png" style="width: 250px; height: 242px;" /></p>
16+
17+
<pre>
18+
<strong>Input:</strong> room = [[0,0,0],[1,1,0],[0,0,0]]
19+
<strong>Output:</strong> 7
20+
<strong>Explanation:</strong>
21+
The robot cleans the spaces at (0, 0), (0, 1), and (0, 2).
22+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces down.
23+
The robot cleans the spaces at (1, 2), and (2, 2).
24+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces left.
25+
The robot cleans the spaces at (2, 1), and (2, 0).
26+
The robot has cleaned all 7 empty spaces, so return 7.
27+
</pre>
28+
29+
<p><strong>Example 2:</strong><br />
30+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2000-2099/2061.Number%20of%20Spaces%20Cleaning%20Robot%20Cleaned/images/image-20211101204736-2.png" style="width: 250px; height: 245px;" /></p>
31+
32+
<pre>
33+
<strong>Input:</strong> room = [[0,1,0],[1,0,0],[0,0,0]]
34+
<strong>Output:</strong> 1
35+
<strong>Explanation:</strong>
36+
The robot cleans the space at (0, 0).
37+
The robot hits an object, so it turns 90 degrees clockwise and now faces down.
38+
The robot hits an object, so it turns 90 degrees clockwise and now faces left.
39+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces up.
40+
The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces right.
41+
The robot is back at its starting position.
42+
The robot has cleaned 1 space, so return 1.
43+
</pre>
44+
45+
<p>&nbsp;</p>
46+
<p><strong>Constraints:</strong></p>
47+
48+
<ul>
49+
<li><code>m == room.length</code></li>
50+
<li><code>n == room[r].length</code></li>
51+
<li><code>1 &lt;= m, n &lt;= 300</code></li>
52+
<li><code>room[r][c]</code> is either <code>0</code> or <code>1</code>.</li>
53+
<li><code>room[0][0] == 0</code></li>
54+
</ul>
55+
56+
## Solutions
57+
58+
<!-- tabs:start -->
59+
60+
### **Python3**
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
```java
69+
70+
```
71+
72+
### **...**
73+
74+
```
75+
76+
```
77+
78+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# [2062. 统计字符串中的元音子字符串](https://leetcode-cn.com/problems/count-vowel-substrings-of-a-string)
2+
3+
[English Version](/solution/2000-2099/2062.Count%20Vowel%20Substrings%20of%20a%20String/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p><strong>子字符串</strong> 是字符串中的一个连续(非空)的字符序列。</p>
10+
11+
<p><strong>元音子字符串</strong> 是 <strong>仅</strong> 由元音(<code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code> 和 <code>'u'</code>)组成的一个子字符串,且必须包含 <strong>全部五种</strong> 元音。</p>
12+
13+
<p>给你一个字符串 <code>word</code> ,统计并返回 <code>word</code> 中 <strong>元音子字符串的数目</strong> 。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre>
20+
<strong>输入:</strong>word = "aeiouu"
21+
<strong>输出:</strong>2
22+
<strong>解释:</strong>下面列出 word 中的元音子字符串(斜体加粗部分):
23+
- "<em><strong>aeiou</strong></em>u"
24+
- "<strong><em>aeiouu</em></strong>"
25+
</pre>
26+
27+
<p><strong>示例 2:</strong></p>
28+
29+
<pre>
30+
<strong>输入:</strong>word = "unicornarihan"
31+
<strong>输出:</strong>0
32+
<strong>解释:</strong>word 中不含 5 种元音,所以也不会存在元音子字符串。
33+
</pre>
34+
35+
<p><strong>示例 3:</strong></p>
36+
37+
<pre>
38+
<strong>输入:</strong>word = "cuaieuouac"
39+
<strong>输出:</strong>7
40+
<strong>解释:</strong>下面列出 word 中的元音子字符串(斜体加粗部分):
41+
- "c<em><strong>uaieuo</strong></em>uac"
42+
- "c<em><strong>uaieuou</strong></em>ac"
43+
- "c<em><strong>uaieuoua</strong></em>c"
44+
- "cu<em><strong>aieuo</strong></em>uac"
45+
- "cu<em><strong>aieuou</strong></em>ac"
46+
- "cu<em><strong>aieuoua</strong></em>c"
47+
- "cua<em><strong>ieuoua</strong></em>c"</pre>
48+
49+
<p><strong>示例 4:</strong></p>
50+
51+
<pre>
52+
<strong>输入:</strong>word = "bbaeixoubb"
53+
<strong>输出:</strong>0
54+
<strong>解释:</strong>所有包含全部五种元音的子字符串都含有辅音,所以不存在元音子字符串。
55+
</pre>
56+
57+
<p>&nbsp;</p>
58+
59+
<p><strong>提示:</strong></p>
60+
61+
<ul>
62+
<li><code>1 &lt;= word.length &lt;= 100</code></li>
63+
<li><code>word</code> 仅由小写英文字母组成</li>
64+
</ul>
65+
66+
67+
## 解法
68+
69+
<!-- 这里可写通用的实现逻辑 -->
70+
71+
<!-- tabs:start -->
72+
73+
### **Python3**
74+
75+
<!-- 这里可写当前语言的特殊实现逻辑 -->
76+
77+
```python
78+
79+
```
80+
81+
### **Java**
82+
83+
<!-- 这里可写当前语言的特殊实现逻辑 -->
84+
85+
```java
86+
87+
```
88+
89+
### **...**
90+
91+
```
92+
93+
```
94+
95+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [2062. Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string)
2+
3+
[中文文档](/solution/2000-2099/2062.Count%20Vowel%20Substrings%20of%20a%20String/README.md)
4+
5+
## Description
6+
7+
<p>A <strong>substring</strong> is a contiguous (non-empty) sequence of characters within a string.</p>
8+
9+
<p>A <strong>vowel substring</strong> is a substring that <strong>only</strong> consists of vowels (<code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#39;</code>) and has <strong>all five</strong> vowels present in it.</p>
10+
11+
<p>Given a string <code>word</code>, return <em>the number of <strong>vowel substrings</strong> in</em> <code>word</code>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> word = &quot;aeiouu&quot;
18+
<strong>Output:</strong> 2
19+
<strong>Explanation:</strong> The vowel substrings of word are as follows (underlined):
20+
- &quot;<strong><u>aeiou</u></strong>u&quot;
21+
- &quot;<strong><u>aeiouu</u></strong>&quot;
22+
</pre>
23+
24+
<p><strong>Example 2:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> word = &quot;unicornarihan&quot;
28+
<strong>Output:</strong> 0
29+
<strong>Explanation:</strong> Not all 5 vowels are present, so there are no vowel substrings.
30+
</pre>
31+
32+
<p><strong>Example 3:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> word = &quot;cuaieuouac&quot;
36+
<strong>Output:</strong> 7
37+
<strong>Explanation:</strong> The vowel substrings of word are as follows (underlined):
38+
- &quot;c<strong><u>uaieuo</u></strong>uac&quot;
39+
- &quot;c<strong><u>uaieuou</u></strong>ac&quot;
40+
- &quot;c<strong><u>uaieuoua</u></strong>c&quot;
41+
- &quot;cu<strong><u>aieuo</u></strong>uac&quot;
42+
- &quot;cu<strong><u>aieuou</u></strong>ac&quot;
43+
- &quot;cu<strong><u>aieuoua</u></strong>c&quot;
44+
- &quot;cua<strong><u>ieuoua</u></strong>c&quot;</pre>
45+
46+
<p><strong>Example 4:</strong></p>
47+
48+
<pre>
49+
<strong>Input:</strong> word = &quot;bbaeixoubb&quot;
50+
<strong>Output:</strong> 0
51+
<strong>Explanation:</strong> The only substrings that contain all five vowels also contain consonants, so there are no vowel substrings.
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>1 &lt;= word.length &lt;= 100</code></li>
59+
<li><code>word</code> consists of lowercase English letters only.</li>
60+
</ul>
61+
62+
## Solutions
63+
64+
<!-- tabs:start -->
65+
66+
### **Python3**
67+
68+
```python
69+
70+
```
71+
72+
### **Java**
73+
74+
```java
75+
76+
```
77+
78+
### **...**
79+
80+
```
81+
82+
```
83+
84+
<!-- tabs:end -->

0 commit comments

Comments
 (0)