(haystack: String, needle: String)
| 15 | |
| 16 | impl Solution { |
| 17 | pub fn str_str(haystack: String, needle: String) -> i32 { |
| 18 | if needle.len() == 0 { return 0 } |
| 19 | if needle.len() > haystack.len() { return -1 } |
| 20 | if haystack[..] == needle[..] { return 0 } |
| 21 | let win = needle.len(); |
| 22 | for i in 0..haystack.len() - win + 1 { |
| 23 | if needle == haystack[i..i + win] { |
| 24 | return i as i32 |
| 25 | } |
| 26 | } |
| 27 | -1 |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | #[cfg(test)] |
nothing calls this directly
no outgoing calls
no test coverage detected