classSolution {publiccharfindTheDifference(String s,String t) {if (s.length() ==0) {returnt.charAt(0); }char res ='\0';char[] map =newchar[26];for (char c :t.toCharArray()) { map[c -'a']++; }for (char c :s.toCharArray()) { map[c -'a']--; }for (int i =0; i <26; i++) {if (map[i] !=0) { res = (char)(i +'a'); } }return res; }}
use bit
T: O(n)
S: O(1)
classSolution {publiccharfindTheDifference(String s,String t) {if (s.length() ==0) {returnt.charAt(0); }char res ='\0';for (int i =0; i <s.length(); i++) { res ^=s.charAt(i); res ^=t.charAt(i); } res ^=t.charAt(t.length()-1);return res; }}