summaryrefslogtreecommitdiff
path: root/extra-characters-in-a-string/src
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2024-06-27 11:30:16 +0200
committerOrangerot <purple@orangerot.dev>2024-06-27 11:30:16 +0200
commit4b0a6a01b051a4ebfbc17661d14cb23fe4f275fb (patch)
tree0072cca328fe5adb2ed61004010228ff85e2164d /extra-characters-in-a-string/src
Initial commitHEADmain
Diffstat (limited to 'extra-characters-in-a-string/src')
-rw-r--r--extra-characters-in-a-string/src/main.rs23
1 files changed, 23 insertions, 0 deletions
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<String>) -> i32 {
+ for i in 0..s.len() {
+ for w in dictionary {
+ s.starts_with(w);
+ }
+ }
+ 1
+}