Open rocksc30 opened 1 year ago
class Solution { public char findTheDifference(String s, String t) { int[] sa = new int[26]; int[] ta = new int[26]; int sLen = s.length(); for(int i = 0; i < sLen; i++){ sa[s.charAt(i) - 'a']++; ta[t.charAt(i) - 'a']++; } ta[t.charAt(sLen) - 'a']++; for(int i = 0; i < 26; i++){ if(sa[i] != ta[i]){ return (char)('a' + i); } } return 'a'; } }