Because the character can be duplicated, so we cannot use HashSet.
This is easy if using bucket:
public char findTheDifference(String s, String t) { int[] buckets = new int[26]; for(char c: s.toCharArray()){ buckets[c-'a']++; } for(char c: t.toCharArray()){ buckets[c-'a']--; } for(int i=0;i<buckets.length;i++){ if(buckets[i]<0) return (char)('a'+i); } return '*'; }