Skip to content

Commit

Permalink
practice leetcode - find the index of the first occurrence in a string
Browse files Browse the repository at this point in the history
  • Loading branch information
vuquang23 committed Jan 29, 2025
1 parent 368628a commit e164013
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "find_the_index_of_the_first_occurence_in_a_string"
version = "0.1.0"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string

struct Solution;

impl Solution {
pub fn str_str(haystack: String, needle: String) -> i32 {
match haystack.find(&needle) {
Some(z) => z as i32,
None => -1,
}
}
}

fn main() {
let result = Solution::str_str("sadbutsad".to_string(), "sad".to_string());
println!("{result}")
}

0 comments on commit e164013

Please sign in to comment.