|
1 | | -# 459. Repeated Substring Pattern - LeetCode Solution |
2 | | -LeetCode English link: [459. Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) |
3 | | - |
4 | | -LeetCode Chinese link: [459. 重复的子字符串](https://leetcode.cn/problems/repeated-substring-pattern) |
5 | | - |
6 | | -[中文题解](#中文题解) |
7 | | - |
8 | | -## LeetCode problem description |
9 | | -Given a string `s`, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. |
| 1 | +# 459. 重复的子字符串 - 力扣题解最佳实践 |
| 2 | +力扣链接:[459. 重复的子字符串](https://leetcode.cn/problems/repeated-substring-pattern), 难度: **简单**。 |
10 | 3 |
|
11 | | -Difficulty: **Easy** |
| 4 | +## 力扣“459. 重复的子字符串”问题描述 |
| 5 | +给定一个非空的字符串 `s` ,检查是否可以通过由它的一个子串重复多次构成。 |
12 | 6 |
|
13 | | -### [Example 1] |
14 | | -**Input**: `s = "abcabcabcabc"` |
| 7 | +### [示例 1] |
| 8 | +**输入**: `s = "abcabcabcabc"` |
15 | 9 |
|
16 | | -**Output**: `true` |
| 10 | +**输出**: `true` |
17 | 11 |
|
18 | | -**Explanation**: `It is the substring "abc" four times or the substring "abcabc" twice.` |
| 12 | +**解释**: `可由子串 "abc" 重复四次构成。 (或子串 "abcabc" 重复两次构成。)` |
19 | 13 |
|
20 | | -### [Example 2] |
21 | | -**Input**: `s = "aba"` |
| 14 | +### [示例 2] |
| 15 | +**输入**: `s = "aba"` |
22 | 16 |
|
23 | | -**Output**: `false` |
| 17 | +**输出**: `false` |
24 | 18 |
|
25 | | -### [Constraints] |
| 19 | +### [约束] |
26 | 20 | - `1 <= s.length <= 10000` |
27 | | -- `s` consists of lowercase English letters. |
28 | | - |
29 | | -## Intuition behind the Solution |
30 | | -[中文题解](#中文题解) |
| 21 | +- `s` 由小写英文字母组成 |
31 | 22 |
|
32 | | -The key to solving this problem is to see clearly that if `s` can be obtained by repeating the substring, then the starting letter of the substring must be `s[0]`. |
33 | | -Once you understand this, the scope of substring investigation is greatly narrowed. |
| 23 | +## 思路 |
| 24 | +解决本问题的关键是要看清楚一点:通过子串的重复能得到`s`,那么子串的起始字母一定是`s[0]`。想明白了这一点,子串的排查范围就大大缩小了。 |
34 | 25 |
|
35 | | -## Complexity |
36 | | -* Time: `O(N * N)`. |
37 | | -* Space: `O(N)`. |
| 26 | +## 复杂度 |
| 27 | +* 时间:`O(N * N)`。 |
| 28 | +* 空间:`O(N)`。 |
38 | 29 |
|
39 | 30 | ## Python |
40 | 31 | ```python |
@@ -93,24 +84,3 @@ var repeatedSubstringPattern = function (s) { |
93 | 84 | ``` |
94 | 85 | // Welcome to create a PR to complete the code of this language, thanks! |
95 | 86 | ``` |
96 | | - |
97 | | -## 力扣“459. 重复的子字符串”问题描述 |
98 | | -力扣链接:[459. 重复的子字符串](https://leetcode.cn/problems/repeated-substring-pattern), 难度: **简单**。 |
99 | | - |
100 | | -给定一个非空的字符串 `s` ,检查是否可以通过由它的一个子串重复多次构成。 |
101 | | - |
102 | | -### [示例 1] |
103 | | -**输入**: `s = "abcabcabcabc"` |
104 | | - |
105 | | -**输出**: `true` |
106 | | - |
107 | | -**解释**: `可由子串 "abc" 重复四次构成。 (或子串 "abcabc" 重复两次构成。)` |
108 | | - |
109 | | -### [示例 2] |
110 | | -**输入**: `s = "aba"` |
111 | | - |
112 | | -**输出**: `false` |
113 | | - |
114 | | -# 中文题解 |
115 | | -## 思路 |
116 | | -解决本问题的关键是要看清楚一点:通过子串的重复能得到`s`,那么子串的起始字母一定是`s[0]`。想明白了这一点,子串的排查范围就大大缩小了。 |
0 commit comments