feat: couple more lessons

This commit is contained in:
2024-11-13 00:20:16 +01:00
parent 6ad0ec2fc9
commit d078910cbe
4 changed files with 62 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
pub fn longest_palindrome(value: &str) -> String {
let mut lp: String = "0".to_string();
let input_size = value.len() - 1;
for pal_size in 2..=input_size {
for i in 0..input_size {
if input_size - i < pal_size {
break;
}
if let Some(slice) = value.get(i..(i + pal_size - 1)) {
// let reverted_slice = slice.chars().rev().collect::<String>();
// if string was mutable, we count use .reserve()
let reverted_slice = slice.chars().rev().collect::<String>();
if slice == reverted_slice {
lp = reverted_slice;
break;
}
}
}
}
lp
}