From 4b0a6a01b051a4ebfbc17661d14cb23fe4f275fb Mon Sep 17 00:00:00 2001 From: Orangerot Date: Thu, 27 Jun 2024 11:30:16 +0200 Subject: Initial commit --- extra-characters-in-a-string/Cargo.toml | 8 ++++++++ extra-characters-in-a-string/src/main.rs | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 extra-characters-in-a-string/Cargo.toml create mode 100644 extra-characters-in-a-string/src/main.rs (limited to 'extra-characters-in-a-string') diff --git a/extra-characters-in-a-string/Cargo.toml b/extra-characters-in-a-string/Cargo.toml new file mode 100644 index 0000000..7f2bfde --- /dev/null +++ b/extra-characters-in-a-string/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "extra-characters-in-a-string" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/extra-characters-in-a-string/src/main.rs b/extra-characters-in-a-string/src/main.rs new file mode 100644 index 0000000..f803964 --- /dev/null +++ b/extra-characters-in-a-string/src/main.rs @@ -0,0 +1,23 @@ +fn main() { + let tests = vec![ + ("leetscode", vec!["leet","code","leetcode"], 1), + ("sayhelloworld", vec!["hello","world"], 3), + ]; + + for test in tests { + let result = min_extra_char( + test.0.to_string(), + test.1.iter().map(|s| s.to_string()).collect() + ); + println!("{} has {} should be {}", test.0, result, test.2); + } +} + +fn min_extra_char(s: String, dictionary: Vec) -> i32 { + for i in 0..s.len() { + for w in dictionary { + s.starts_with(w); + } + } + 1 +} -- cgit v1.2.3