problem
884. Uncommon Words from Two Sentences
题意:只要在两个句子中单词出现总次数大于1次即可。
注意掌握istringstream/map/set的使用方法。
solution:
class Solution { public: vector<string> uncommonFromSentences(string A, string B) { vector<string> res; unordered_map<string, int> tmp; istringstream iss(A+" "+B);//err.. while(iss >> A) tmp[A]++; for(auto a:tmp) { if(a.second==1) res.push_back(a.first);//err.. } return res; } };
参考
1. Leetcode_easy_884. Uncommon Words from Two Sentences;
2. grandyang;
3. discuss;
完