class Solution {
public:
vector<string> uncommonFromSentences(string s1, string s2) {
unordered_map<string,int> freq;
auto insert = [&](const string&s)
{
//介绍流的输入和输出操作
stringstream ss(s);
string word;
//一个字符串按照间隔符拆成多个字符串
while(ss>>word)
{
++freq[move(word)];
}
};
insert(s1);
insert(s2);
vector<string> ans;
for(const auto&[word,occ]:freq)
{
if(occ==1)
{
ans.push_back(word);
}
}
return ans;
}
};
两句话中的不常见单词
最新推荐文章于 2024-07-29 22:53:13 发布