-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
practice leetcode - find the index of the first occurrence in a string
- Loading branch information
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/practice/leetcode/find_the_index_of_the_first_occurence_in_a_string/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/practice/leetcode/find_the_index_of_the_first_occurence_in_a_string/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
17 changes: 17 additions & 0 deletions
17
src/practice/leetcode/find_the_index_of_the_first_occurence_in_a_string/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") | ||
} |