From 673a4a93888148ad405746e2c845487bb4d6bb1c Mon Sep 17 00:00:00 2001 From: jackfiled Date: Mon, 22 Apr 2024 10:00:39 +0800 Subject: [PATCH] 20240422 Finished --- src/problem/mod.rs | 3 ++- ...dex_of_the_first_occurrence_in_a_string.rs | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/problem/p28_find_the_index_of_the_first_occurrence_in_a_string.rs diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 0360ce6..cfb95fa 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -108,4 +108,5 @@ mod p134_gas_station; mod p135_candy; mod p42_trapping_rain_water; mod p58_length_of_last_word; -mod p151_reverse_words_in_a_string; \ No newline at end of file +mod p151_reverse_words_in_a_string; +mod p28_find_the_index_of_the_first_occurrence_in_a_string; \ No newline at end of file diff --git a/src/problem/p28_find_the_index_of_the_first_occurrence_in_a_string.rs b/src/problem/p28_find_the_index_of_the_first_occurrence_in_a_string.rs new file mode 100644 index 0000000..a0d8c7d --- /dev/null +++ b/src/problem/p28_find_the_index_of_the_first_occurrence_in_a_string.rs @@ -0,0 +1,27 @@ +/** + * [28] Find the Index of the First Occurrence in a String + */ +pub struct Solution {} + + +// submission codes start here + +impl Solution { + pub fn str_str(haystack: String, needle: String) -> i32 { + match haystack.find(&needle) { + Some(pos) => pos as i32, + None => -1 + } + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_28() { + } +}