mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0028.实现strStr.md
This commit is contained in:
@ -1303,7 +1303,8 @@ impl Solution {
|
||||
|
||||
```rust
|
||||
impl Solution {
|
||||
pub fn get_next(mut next: Vec<i32>, s: &Vec<char>) -> Vec<i32> {
|
||||
pub fn get_next(next_len: usize, s: &Vec<char>) -> Vec<i32> {
|
||||
let mut next = vec![-1; next_len];
|
||||
let mut j = -1;
|
||||
for i in 1..s.len() {
|
||||
while j >= 0 && s[(j + 1) as usize] != s[i] {
|
||||
@ -1328,8 +1329,7 @@ impl Solution {
|
||||
needle.chars().collect::<Vec<char>>(),
|
||||
);
|
||||
let mut j = -1;
|
||||
let mut next = vec![-1; needle.len()];
|
||||
next = Self::get_next(next, &needle_chars);
|
||||
let next = Self::get_next(needle.len(), &needle_chars);
|
||||
for (i, v) in haystack_chars.into_iter().enumerate() {
|
||||
while j >= 0 && v != needle_chars[(j + 1) as usize] {
|
||||
j = next[j as usize];
|
||||
|
Reference in New Issue
Block a user