add initial data

This commit is contained in:
timeshifter committed 2026-09-04 15:56:45 +02:00
1 parent 048a82b101
commit 51d935d06b
66 files changed
+1329

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "longest-common-prefix"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "longest-common-prefix"
version = "0.1.0"
edition = "2024"
[dependencies]
+28
View File
@@ -0,0 +1,28 @@
fn main() {
println!("Hello, world!");
}
fn longest_common_prefix(strs: Vec<String>) -> String {
let mut strs = strs;
strs.sort_by_key(|x| x.len());
let chars = strs
.into_iter()
.map(|s| s.chars().collect::<Vec<char>>())
.collect::<Vec<_>>();
let first_word_chars = chars.first().unwrap();
let mut result = String::new();
for (i, c) in first_word_chars.iter().enumerate() {
if chars.iter().all(|vc| vc[i] == *c) {
result.push(*c);
} else {
return result;
}
}
result
}