389. 找不同

 1 class Solution 
 2 {
 3 public:
 4     char findTheDifference(string s, string t) 
 5     {
 6         unordered_map<char,int> hash;
 7         for(auto a : s) hash[a] ++;
 8         for(auto a : t)
 9         {
10             if(hash.find(a) == hash.end()) return a;
11             else
12             {
13                 hash[a] --;
14                 if(hash[a] == 0) hash.erase(a);
15             }
16         }
17         return ' ';
18     }
19 };

 

posted @ 2020-04-27 17:49  Jinxiaobo0509  阅读(114)  评论(0)    收藏  举报