My Very Fast Solution With An Array


  • 0
    M

    My solution will waste 22 array space but very fast.

    if (moves.Length % 2 != 0)
        return false;
    
    int[] Alphabet = new int[26];
    foreach (char c in moves)
           Alphabet[c - 65]++;
    
    if (Alphabet[3] == Alphabet[20] && Alphabet[11] == Alphabet[17])
        return true;
    else
        return false;
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.