diff options
Diffstat (limited to '0028')
| -rw-r--r-- | 0028/Cargo.lock | 7 | ||||
| -rw-r--r-- | 0028/Cargo.toml | 6 | ||||
| -rw-r--r-- | 0028/src/main.rs | 20 |
3 files changed, 33 insertions, 0 deletions
diff --git a/0028/Cargo.lock b/0028/Cargo.lock new file mode 100644 index 0000000..270e521 --- /dev/null +++ b/0028/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "p28" +version = "0.1.0" diff --git a/0028/Cargo.toml b/0028/Cargo.toml new file mode 100644 index 0000000..c78abd7 --- /dev/null +++ b/0028/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "p28" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/0028/src/main.rs b/0028/src/main.rs new file mode 100644 index 0000000..c830ac4 --- /dev/null +++ b/0028/src/main.rs @@ -0,0 +1,20 @@ +impl Solution { + pub fn str_str(haystack: String, needle: String) -> i32 { + if needle.len() > haystack.len() { return -1; } + for i in 0..haystack.len() - needle.len()+1 { + let mut failed = false; + for j in 0..needle.len() { + if haystack.as_bytes()[i+j] != needle.as_bytes()[j] { + failed = true; + break; + } + } + if !failed { return i as i32; } + } + -1 + } +} +struct Solution { } +fn main() { + println!("{}", Solution::str_str("abaaa".to_string(), "abb".to_string())); +}
\ No newline at end of file |
