Answers for "check if a string contains consecutive letters that occur only once"

0

check if a string contains consecutive letters that occur only once

// Check if a string contains consecutive letters that occur only once
fn solve(s: &str) -> bool {
    let mut vlist: Vec<char> = s.chars().collect();
    vlist.sort();
    vlist[..]
        .windows(2)
        .all(|slice| slice[1] as u8 == slice[0] as u8 + 1)
}

fn main() {
    let list = "dabc";  // true
    println!("Consecutive letters = {} ", solve(list));
}
Posted by: Guest on August-30-2021

Code answers related to "check if a string contains consecutive letters that occur only once"

Browse Popular Code Answers by Language