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

[pull] master from youngyangyang04:master #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 20 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jul 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
607e4eb
更新 哈希表理论基础 排版格式修复
jinbudaily Jul 19, 2023
c628aa6
更新 0242.有效的字母异位词 排版格式修复
jinbudaily Jul 19, 2023
19dfa98
更新 0349.两个数组的交集 排版格式修复
jinbudaily Jul 19, 2023
764b3e9
更新 0202.快乐数 排版格式修复
jinbudaily Jul 19, 2023
23950d1
更新 001.两数之和 排版格式修复
jinbudaily Jul 19, 2023
2948791
更新 0454.四数相加II 排版格式修复
jinbudaily Jul 19, 2023
0922ede
更新 0383.赎金信 排版格式修复
jinbudaily Jul 19, 2023
eb2cdf2
更新 0015.三数之和 排版格式修复
jinbudaily Jul 19, 2023
3fe673d
更新 0018.四数之和 排版格式修复
jinbudaily Jul 19, 2023
ddee6ad
更新 哈希表总结 排版格式修复
jinbudaily Jul 19, 2023
4ae8843
Merge branch 'master' of github.com:jinbudaily/leetcode-master
jinbudaily Jul 19, 2023
00ef608
更新 0344.反转字符串 排版格式修复
jinbudaily Jul 19, 2023
5cb2501
更新 0541.反转字符串 排版格式修复
jinbudaily Jul 19, 2023
963eb8f
更新 剑指Offer05.替换空格 排版格式修复
jinbudaily Jul 19, 2023
e70ca92
更新 0151.反转字符串中的单词 排版格式修复
jinbudaily Jul 19, 2023
370a4d1
更新 剑指Offer58-II.左旋转字符串 排版格式修复
jinbudaily Jul 19, 2023
5acebcc
更新 0028.实现strStr 排版格式修复
jinbudaily Jul 19, 2023
202dd38
更新 0459.重复的字符串 排版格式修复
jinbudaily Jul 19, 2023
4fe1f08
更新 字符串总结 排版格式修复
jinbudaily Jul 19, 2023
406cada
Merge pull request #2191 from jinbudaily/master
youngyangyang04 Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
更新 0459.重复的字符串 排版格式修复
  • Loading branch information
jinbudaily committed Jul 19, 2023
commit 202dd382d29eb34f311d5f35f001255b2b770402
35 changes: 16 additions & 19 deletions problems/0459.重复的子字符串.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>




> KMP算法还能干这个

# 459.重复的子字符串
Expand All @@ -29,9 +27,11 @@
* 输出: True
* 解释: 可由子字符串 "abc" 重复四次构成。 (或者子字符串 "abcabc" 重复两次构成。)

# 思路
## 算法公开课

**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[字符串这么玩,可有点难度! | LeetCode:459.重复的子字符串](https://www.bilibili.com/video/BV1cg41127fw),相信结合视频再看本篇题解,更有助于大家对本题的理解**。

针对本题,我录制了视频讲解:[字符串这么玩,可有点难度! | LeetCode:459.重复的子字符串](https://www.bilibili.com/video/BV1cg41127fw),结合本题解一起看,事半功倍!
## 思路


暴力的解法, 就是一个for循环获取 子串的终止位置, 然后判断子串是否能重复构成字符串,又嵌套一个for循环,所以是O(n^2)的时间复杂度。
Expand All @@ -44,7 +44,7 @@

主要讲一讲移动匹配 和 KMP两种方法。

## 移动匹配
### 移动匹配

当一个字符串s:abcabc,内部由重复的子串组成,那么这个字符串的结构一定是这样的:

Expand Down Expand Up @@ -80,9 +80,9 @@ public:

如果我们做过 [28.实现strStr](https://programmercarl.com/0028.实现strStr.html) 题目的话,其实就知道,**实现一个 高效的算法来判断 一个字符串中是否出现另一个字符串是很复杂的**,这里就涉及到了KMP算法。

## KMP
### KMP

### 为什么会使用KMP
#### 为什么会使用KMP
以下使用KMP方式讲解,强烈建议大家先把以下两个视频看了,理解KMP算法,再来看下面讲解,否则会很懵。

* [视频讲解版:帮你把KMP算法学个通透!(理论篇)](https://www.bilibili.com/video/BV1PD4y1o7nd/)
Expand All @@ -105,7 +105,7 @@ KMP算法中next数组为什么遇到字符不匹配的时候可以找到上一
![图三](https://code-thinking-1253855093.file.myqcloud.com/pics/20220728205249.png)


### 如何找到最小重复子串
#### 如何找到最小重复子串

这里有同学就问了,为啥一定是开头的ab呢。 其实最关键还是要理解 最长相等前后缀,如图:

Expand All @@ -123,7 +123,7 @@ KMP算法中next数组为什么遇到字符不匹配的时候可以找到上一

正是因为 最长相等前后缀的规则,当一个字符串由重复子串组成的,最长相等前后缀不包含的子串就是最小重复子串。

### 简单推理
#### 简单推理

这里再给出一个数学推导,就容易理解很多。

Expand Down Expand Up @@ -229,7 +229,7 @@ public:

## 其他语言版本

Java:
### Java:

```java
class Solution {
Expand Down Expand Up @@ -261,8 +261,7 @@ class Solution {
}
```


Python:
### Python:

(版本一) 前缀表 减一
```python
Expand Down Expand Up @@ -346,8 +345,7 @@ class Solution:
return False
```


Go:
### Go:

这里使用了前缀表统一减一的实现方式

Expand Down Expand Up @@ -405,7 +403,7 @@ func repeatedSubstringPattern(s string) bool {
}
```

JavaScript版本
### JavaScript:

> 前缀表统一减一

Expand Down Expand Up @@ -479,7 +477,7 @@ var repeatedSubstringPattern = function (s) {
};
```

TypeScript:
### TypeScript:

> 前缀表统一减一

Expand Down Expand Up @@ -539,8 +537,7 @@ function repeatedSubstringPattern(s: string): boolean {
};
```


Swift:
### Swift:

> 前缀表统一减一
```swift
Expand Down Expand Up @@ -623,7 +620,7 @@ Swift:
}
```

Rust:
### Rust:

>前缀表统一不减一
```Rust
Expand Down

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