From 856907e3d596f6796b4817aa6b80a26e6dbb73d6 Mon Sep 17 00:00:00 2001 From: fw_qaq <82551626+Jack-Zhang-1314@users.noreply.github.com> Date: Tue, 25 Oct 2022 23:26:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update=200459.=E9=87=8D=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=E5=AD=90=E5=AD=97=E7=AC=A6=E4=B8=B2.md=20about=20rust=20?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E8=A1=A8=E7=BB=9F=E4=B8=80=20-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0459.重复的子字符串.md | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md index 18de79d5..378d1a63 100644 --- a/problems/0459.重复的子字符串.md +++ b/problems/0459.重复的子字符串.md @@ -615,6 +615,35 @@ impl Solution { } ``` +>前缀表统一减一 + +```rust + pub fn get_next(next_len: usize, s: &Vec) -> Vec { + let mut next = vec![-1; next_len]; + let mut j = -1; + for i in 1..s.len() { + while j >= 0 && s[i] != s[(j + 1) as usize] { + j = next[j as usize]; + } + if s[i] == s[(j + 1) as usize] { + j += 1; + } + next[i] = j; + } + next + } + pub fn repeated_substring_pattern(s: String) -> bool { + let s_chars = s.chars().collect::>(); + let next = Self::get_next(s_chars.len(), &s_chars); + if next[s_chars.len() - 1] >= 0 + && s_chars.len() % (s_chars.len() - (next[s_chars.len() - 1] + 1) as usize) == 0 + { + return true; + } + false + } +``` +

From f386e3ca68c602c84f875ab1b6538a41e000459b Mon Sep 17 00:00:00 2001 From: fw_qaq <82551626+Jack-Zhang-1314@users.noreply.github.com> Date: Tue, 25 Oct 2022 23:27:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Update=200459.=E9=87=8D=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=E5=AD=90=E5=AD=97=E7=AC=A6=E4=B8=B2.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0459.重复的子字符串.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md index 378d1a63..b7d86880 100644 --- a/problems/0459.重复的子字符串.md +++ b/problems/0459.重复的子字符串.md @@ -618,6 +618,7 @@ impl Solution { >前缀表统一减一 ```rust +impl Solution { pub fn get_next(next_len: usize, s: &Vec) -> Vec { let mut next = vec![-1; next_len]; let mut j = -1; @@ -642,6 +643,7 @@ impl Solution { } false } +} ```