Loading RustViz Engine...
Find the longest common prefix across an array of string slices.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn longest_common_prefix<'a>(strs: &[&'a str]) -> &'a str {
if strs.is_empty() { return ""; }
let first = strs[0];
for (i, byte) in first.bytes().enumerate() {
for s in &strs[1..] {
if i >= s.len() || s.as_bytes()[i] != byte {
return &first[..i];
}
}
}
first
}