7ms


  • 0
    P
    public class Solution {
        public char findTheDifference(String s, String t) {
            int [] alphabets = new int[26]; char ans = ' ';
            char[] sc = s.toCharArray();
            char[] tc = t.toCharArray();
            for(char cs:sc) {alphabets[(int)cs - (int)'a']--;}
            for(char ct:tc) {alphabets[(int)ct -(int)'a']++;}
            for(int i=0; i<alphabets.length; i++) {if(alphabets[i]>0) return (char) ('a' + i);} 
            
            return ans;
           
        }
    }

Log in to reply
 

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