28. Find the Index of the First Occurrence in a String
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 45% Topics: Two Pointers, String, String Matching
View full problem on LeetCode Reading material
Reference solution (spoiler · rust)
pub struct Solution {}
impl Solution {
pub fn strStr(haystack: String, needle: String) -> i32 {
if needle.is_empty() {
return 0;
}
haystack.find(&needle).map_or(-1_i32, |v| v as i32)
}
}
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions