C# Solution


  • 0
    M
    public char FindTheDifference(string s, string t) 
    {
        int[] char_set = new int[26];
        
        foreach (char c in s)
        {
            char_set[c - 'a']++; 
        }
        
        foreach (char c in t)
        {
            char_set[c - 'a']--;
            if (char_set[c - 'a'] < 0) return c; 
        }
    
        return ' '; 
    }

Log in to reply
 

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