pub fn check_permutation_efficient(word: &str, permutation: &str) -> bool {
    if word.len() != permutation.len() {
        return false;
    }

    let mut letters: [u8; 128] = [0; 128];

    word.chars().for_each(|ch| {
        letters[ch as usize] += 1;
    });

    (0..permutation.len()).for_each(|i| {
        let c = permutation.chars().nth(i).unwrap();
        letters[c as usize] -= 1;
    });

    true
}
/// This function is better if efficient is important, maybe not so readable as the first function
/// regarding the assumption, always check about he size of the character set, here we assuming it's ASCII
This function is better if efficient is important, maybe not so readable as the first function
regarding the assumption, always check about he size of the character set, here we assuming it's ASCII
This function is better if efficient is important maybe not so readable as the first function regarding the assumption always check about he size of the character set here we assuming it ' s ASCII
pub fn check_permutation_efficient(word: &str, permutation: &str) -> bool {
    if word.len() != permutation.len() {
        return false;
    }
    let mut letters: [u8; 128] = [0; 128];
    word.chars().for_each(|ch| {
        letters[ch as usize] += 1;
    });
    (0..permutation.len()).for_each(|i| {
        let c = permutation.chars().nth(i).unwrap();
        letters[c as usize] -= 1;
    });
    true
}
pub fn check_permutation_efficient ( word : & str , permutation : & str ) -> bool { if word . len ( ) != permutation . len ( ) { return false ; } let mut letters : [ u8 ; 128 ] = [ 0 ; 128 ] ; word . chars ( ) . for_each ( | ch | { letters [ ch as usize ] += 1 ; } ) ; ( 0 .. permutation . len ( ) ) . for_each ( | i | { let c = permutation . chars ( ) . nth ( i ) . unwrap ( ) ; letters [ c as usize ] -= 1 ; } ) ; true }
This function is better if efficient is important, maybe not so readable as the first function
regarding the assumption, always check about he size of the character set, here we assuming it's ASCII
This function is better if efficient is important maybe not so readable as the first function regarding the assumption always check about he size of the character set here we assuming it ' s ASCII
word
&str
permutation
&str
word
&str
permutation
&str