Skip to content

Instantly share code, notes, and snippets.

@bDrwx
Created October 21, 2019 20:42
Show Gist options
  • Save bDrwx/f2165d5b0d20e412d1e42600b8c8c3a2 to your computer and use it in GitHub Desktop.
Save bDrwx/f2165d5b0d20e412d1e42600b8c8c3a2 to your computer and use it in GitHub Desktop.
14. Longest Common Prefix
impl Solution {
pub fn longest_common_prefix(strs: Vec<String>) -> String {
if strs.len() == 0 {
return "".to_string();
}
let mut prefix = strs[0].clone();
for n in 1..strs.len() {
while(!strs[n].contains(&prefix)){
prefix = prefix[..prefix.len()-1].to_string();
}
}
return prefix
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment