Skip to content

Commit 8fcb75b

Browse files
committed
LeetCode 题目描述 1554~1569
1 parent f523d1f commit 8fcb75b

File tree

28 files changed

+2362
-0
lines changed

28 files changed

+2362
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# [1554. 只有一个不同字符的字符串](https://leetcode-cn.com/problems/strings-differ-by-one-character)
2+
3+
[English Version](/solution/1500-1599/1554.Strings Differ by One Character/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
<p>给定一个字符串列表&nbsp;<code>dict</code> ,其中所有字符串的长度都相同。</p>
9+
10+
<p>当存在两个字符串在相同索引处只有一个字符不同时,返回 <code>True</code> ,否则返回 <code>False</code> 。</p>
11+
12+
<p><strong>进阶:</strong>你可以以 O(n*m) 的复杂度解决问题吗?其中 n 是列表 <code>dict</code> 的长度,m 是字符串的长度。</p>
13+
14+
<p>&nbsp;</p>
15+
16+
<p><strong>示例 1:</strong></p>
17+
18+
<pre>
19+
<strong>输入:</strong>dict = [&quot;abcd&quot;,&quot;acbd&quot;, &quot;aacd&quot;]
20+
<strong>输出:</strong>true
21+
<strong>解释:</strong>字符串 &quot;a<strong>b</strong>cd&quot;&quot;a<strong>a</strong>cd&quot; 只在索引 1 处有一个不同的字符。
22+
</pre>
23+
24+
<p><strong>示例 2:</strong></p>
25+
26+
<pre>
27+
<strong>输入:</strong>dict = [&quot;ab&quot;,&quot;cd&quot;,&quot;yz&quot;]
28+
<strong>输出:</strong>false
29+
</pre>
30+
31+
<p><strong>示例 3:</strong></p>
32+
33+
<pre>
34+
<strong>输入:</strong>dict = [&quot;abcd&quot;,&quot;cccc&quot;,&quot;abyd&quot;,&quot;abab&quot;]
35+
<strong>输出:</strong>true
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
40+
<p><strong>提示:</strong></p>
41+
42+
<ul>
43+
<li><code>dict</code>&nbsp;中的字符数小于或等于&nbsp;<code>10^5</code>&nbsp;。</li>
44+
<li><code>dict[i].length == dict[j].length</code></li>
45+
<li><code>dict[i]</code>&nbsp;是互不相同的。</li>
46+
<li><code>dict[i]</code>&nbsp;只包含小写英文字母。</li>
47+
</ul>
48+
49+
50+
51+
## 解法
52+
53+
<!-- 这里可写通用的实现逻辑 -->
54+
55+
56+
<!-- tabs:start -->
57+
58+
### **Python3**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```java
71+
72+
```
73+
74+
### **...**
75+
```
76+
77+
```
78+
79+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# [1554. Strings Differ by One Character](https://leetcode.com/problems/strings-differ-by-one-character)
2+
3+
[中文文档](/solution/1500-1599/1554.Strings Differ by One Character/README.md)
4+
5+
## Description
6+
7+
<p>Given a list&nbsp;of strings <code>dict</code> where all the strings are of the same length.</p>
8+
9+
<p>Return <code>True</code> if there are 2 strings that only differ by 1 character in the same index, otherwise&nbsp;return <code>False</code>.</p>
10+
11+
<p><strong>Follow up:&nbsp;</strong>Could you solve this problem in O(n*m) where n is the length of <code>dict</code> and m is the length of each string.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> dict = [&quot;abcd&quot;,&quot;acbd&quot;, &quot;aacd&quot;]
18+
<strong>Output:</strong> true
19+
<strong>Explanation:</strong> Strings &quot;a<strong>b</strong>cd&quot; and &quot;a<strong>a</strong>cd&quot; differ only by one character in the index 1.
20+
</pre>
21+
22+
<p><strong>Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> dict = [&quot;ab&quot;,&quot;cd&quot;,&quot;yz&quot;]
26+
<strong>Output:</strong> false
27+
</pre>
28+
29+
<p><strong>Example 3:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> dict = [&quot;abcd&quot;,&quot;cccc&quot;,&quot;abyd&quot;,&quot;abab&quot;]
33+
<strong>Output:</strong> true
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li>Number of characters in <code>dict &lt;= 10^5</code></li>
41+
<li><code>dict[i].length == dict[j].length</code></li>
42+
<li><code>dict[i]</code> should be unique.</li>
43+
<li><code>dict[i]</code> contains only lowercase English letters.</li>
44+
</ul>
45+
46+
47+
## Solutions
48+
49+
50+
51+
<!-- tabs:start -->
52+
53+
### **Python3**
54+
55+
56+
```python
57+
58+
```
59+
60+
### **Java**
61+
62+
63+
```java
64+
65+
```
66+
67+
### **...**
68+
```
69+
70+
```
71+
72+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# [1556. 千位分隔数](https://leetcode-cn.com/problems/thousand-separator)
2+
3+
[English Version](/solution/1500-1599/1556.Thousand Separator/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
<p>给你一个整数&nbsp;<code>n</code>,请你每隔三位添加点(即 &quot;.&quot; 符号)作为千位分隔符,并将结果以字符串格式返回。</p>
9+
10+
<p>&nbsp;</p>
11+
12+
<p><strong>示例 1:</strong></p>
13+
14+
<pre><strong>输入:</strong>n = 987
15+
<strong>输出:</strong>&quot;987&quot;
16+
</pre>
17+
18+
<p><strong>示例 2:</strong></p>
19+
20+
<pre><strong>输入:</strong>n = 1234
21+
<strong>输出:</strong>&quot;1.234&quot;
22+
</pre>
23+
24+
<p><strong>示例 3:</strong></p>
25+
26+
<pre><strong>输入:</strong>n = 123456789
27+
<strong>输出:</strong>&quot;123.456.789&quot;
28+
</pre>
29+
30+
<p><strong>示例 4:</strong></p>
31+
32+
<pre><strong>输入:</strong>n = 0
33+
<strong>输出:</strong>&quot;0&quot;
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
38+
<p><strong>提示:</strong></p>
39+
40+
<ul>
41+
<li><code>0 &lt;= n &lt; 2^31</code></li>
42+
</ul>
43+
44+
45+
46+
## 解法
47+
48+
<!-- 这里可写通用的实现逻辑 -->
49+
50+
51+
<!-- tabs:start -->
52+
53+
### **Python3**
54+
55+
<!-- 这里可写当前语言的特殊实现逻辑 -->
56+
57+
```python
58+
59+
```
60+
61+
### **Java**
62+
63+
<!-- 这里可写当前语言的特殊实现逻辑 -->
64+
65+
```java
66+
67+
```
68+
69+
### **...**
70+
```
71+
72+
```
73+
74+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# [1556. Thousand Separator](https://leetcode.com/problems/thousand-separator)
2+
3+
[中文文档](/solution/1500-1599/1556.Thousand Separator/README.md)
4+
5+
## Description
6+
7+
<p>Given an&nbsp;integer <code>n</code>, add a dot (&quot;.&quot;)&nbsp;as the thousands separator and return it in&nbsp;string format.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong>Example 1:</strong></p>
11+
12+
<pre>
13+
<strong>Input:</strong> n = 987
14+
<strong>Output:</strong> &quot;987&quot;
15+
</pre>
16+
17+
<p><strong>Example 2:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> n = 1234
21+
<strong>Output:</strong> &quot;1.234&quot;
22+
</pre>
23+
24+
<p><strong>Example 3:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> n = 123456789
28+
<strong>Output:</strong> &quot;123.456.789&quot;
29+
</pre>
30+
31+
<p><strong>Example 4:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> n = 0
35+
<strong>Output:</strong> &quot;0&quot;
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>0 &lt;= n &lt; 2^31</code></li>
43+
</ul>
44+
45+
46+
## Solutions
47+
48+
49+
50+
<!-- tabs:start -->
51+
52+
### **Python3**
53+
54+
55+
```python
56+
57+
```
58+
59+
### **Java**
60+
61+
62+
```java
63+
64+
```
65+
66+
### **...**
67+
```
68+
69+
```
70+
71+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [1557. 可以到达所有点的最少点数目](https://leetcode-cn.com/problems/minimum-number-of-vertices-to-reach-all-nodes)
2+
3+
[English Version](/solution/1500-1599/1557.Minimum Number of Vertices to Reach All Nodes/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
<p>给你一个 <strong>有向无环图</strong>&nbsp;, <code>n</code>&nbsp;个节点编号为 <code>0</code>&nbsp;到 <code>n-1</code>&nbsp;,以及一个边数组 <code>edges</code>&nbsp;,其中 <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>]</code>&nbsp;表示一条从点&nbsp;&nbsp;<code>from<sub>i</sub></code>&nbsp;到点&nbsp;<code>to<sub>i</sub></code>&nbsp;的有向边。</p>
9+
10+
<p>找到最小的点集使得从这些点出发能到达图中所有点。题目保证解存在且唯一。</p>
11+
12+
<p>你可以以任意顺序返回这些节点编号。</p>
13+
14+
<p>&nbsp;</p>
15+
16+
<p><strong>示例 1:</strong></p>
17+
18+
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/08/22/5480e1.png" style="height: 181px; width: 231px;"></p>
19+
20+
<pre><strong>输入:</strong>n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]
21+
<strong>输出:</strong>[0,3]
22+
<strong>解释:</strong>从单个节点出发无法到达所有节点。从 0 出发我们可以到达 [0,1,2,5] 。从 3 出发我们可以到达 [3,4,2,5] 。所以我们输出 [0,3] 。</pre>
23+
24+
<p><strong>示例 2:</strong></p>
25+
26+
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/08/22/5480e2.png" style="height: 201px; width: 201px;"></p>
27+
28+
<pre><strong>输入:</strong>n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]
29+
<strong>输出:</strong>[0,2,3]
30+
<strong>解释:</strong>注意到节点 0,3 和 2 无法从其他节点到达,所以我们必须将它们包含在结果点集中,这些点都能到达节点 1 和 4 。
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
35+
<p><strong>提示:</strong></p>
36+
37+
<ul>
38+
<li><code>2 &lt;= n &lt;= 10^5</code></li>
39+
<li><code>1 &lt;= edges.length &lt;= min(10^5, n * (n - 1) / 2)</code></li>
40+
<li><code>edges[i].length == 2</code></li>
41+
<li><code>0 &lt;= from<sub>i,</sub>&nbsp;to<sub>i</sub> &lt; n</code></li>
42+
<li>所有点对&nbsp;<code>(from<sub>i</sub>, to<sub>i</sub>)</code>&nbsp;互不相同。</li>
43+
</ul>
44+
45+
46+
47+
## 解法
48+
49+
<!-- 这里可写通用的实现逻辑 -->
50+
51+
52+
<!-- tabs:start -->
53+
54+
### **Python3**
55+
56+
<!-- 这里可写当前语言的特殊实现逻辑 -->
57+
58+
```python
59+
60+
```
61+
62+
### **Java**
63+
64+
<!-- 这里可写当前语言的特殊实现逻辑 -->
65+
66+
```java
67+
68+
```
69+
70+
### **...**
71+
```
72+
73+
```
74+
75+
<!-- tabs:end -->

0 commit comments

Comments
 (0)