diff options
| author | Mistivia <i@mistivia.com> | 2025-08-22 17:16:46 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-08-22 17:16:46 +0800 |
| commit | fff78815bae72051159a4a4ae5da34bea027317c (patch) | |
| tree | e4f10bf588581f91519a35eeb1cf8ef81ae8e4f6 /src | |
| parent | e8e70c2cf57ab9e1a1d13a3bd53ffb761fef7779 (diff) | |
solve 28
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/p0028.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/bin/p0028.rs b/src/bin/p0028.rs new file mode 100644 index 0000000..c830ac4 --- /dev/null +++ b/src/bin/p0028.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 |
