# LeetCode - 0884. Uncommon Words from Two Sentences ### 題目網址:https://leetcode.com/problems/uncommon-words-from-two-sentences/ ###### tags: `LeetCode` `Easy` `字串` ```cpp= /* -LeetCode format- Problem: 884. Uncommon Words from Two Sentences Difficulty: Easy by Inversionpeter */ class Solution { public: vector<string> uncommonFromSentences(string A, string B) { vector <string> uncommons; map <string, int> counts; int last = 0; for (int i = 1; i != A.size(); ++i) if (A[i] == ' ') { ++counts[A.substr(last, i - last)]; last = i + 1; } if (last != A.size()) ++counts[A.substr(last)]; last = 0; for (int i = 1; i != B.size(); ++i) if (B[i] == ' ') { ++counts[B.substr(last, i - last)]; last = i + 1; } if (last != B.size()) ++counts[B.substr(last)]; for (map <string, int>::iterator i = counts.begin(); i != counts.end(); ++i) if (i->second == 1) uncommons.push_back(i->first); return uncommons; } }; ```