Search
 
SCRIPT & CODE EXAMPLE
 

RUST

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));
}
Comment

PREVIOUS NEXT
Code Example
Rust :: how to convert string to i32 in rust 
Rust :: rust get char at index 
Rust :: does rust support classes 
Rust :: rust lang underscore 
Rust :: rust enum anonymous struct 
Rust :: rust•armanriazi•type•wraper•mutable 
Rust :: armanriazi•rust•interior-mutability•vs•inherited-mutability 
Rust :: Take two integers, return the quotient and remainder, divmod 
Rust :: rust•armanriazi•concept•borrowchecker 
Rust :: armanriazi•rust•error•[E0614]: cannot be dereferenced 
Rust :: armanriazi•rust•dereferencing 
Rust :: armanriazi•rust•thread 
Rust :: armanriazi•rust•concept•mangling 
Rust :: armanriazi•rust•trait•object•safe 
Rust :: rust compiler error 
Lua :: roblox studio teleport on collision 
Lua :: absolute value in lua 
Lua :: roblox what is the difference between __index and __newindex 
Lua :: open gui script 
Lua :: roblox lua brick color randomiser 
Lua :: grepper lua 
Lua :: round to the nearest number lua 
Lua :: datastore roblox 
Lua :: roblox studio pause physics 
Lua :: lua table functions 
Lua :: difference between roblox and minecraft 
Lua :: roblox lua scripts 
Matlab :: matlab set fig zoom 
Matlab :: what is java_home 
Basic :: resttemplate authorization basic 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =