https://leetcode.com/problems/find-the-difference/
思路:把字符串s存到hash表中,相同字母累加;
遍历字符串t,字符对应hash表的字符个数则减一,如果小于0则返回得到结果
class Solution {
public:
char findTheDifference(string s, string t) {
map<char,int> mp;
for(int i = 0;i < s.length();i++){
mp[s[i]] += 1;
}
for(int i = 0;i < t.length();i++){
if(--mp[t[i]] < 0)
{
return t[i];
}
}
return ' ';
}
};