Skip to content

Commit

Permalink
Create 884. Uncommon Words from Two Sentences (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Sep 17, 2024
2 parents 1b4fea4 + 03b68bf commit 6065f37
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 884. Uncommon Words from Two Sentences
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
vector<string> uncommonFromSentences(string s1, string s2) {
string s = s1+ " "+ s2+ " ";
// cout<< s<< endl;
unordered_map<string, int>mpp;

string temp = "";
for(int i = 0; i < s.size(); i++){
if(s[i] == ' '){
cout<<temp<< endl;
mpp[temp]++;
temp = "";
}
else
temp+=s[i];
}
vector<string>ans;
for (auto it :mpp) {
if(it.second == 1)
ans.push_back(it.first);
}
return ans;
}
};

0 comments on commit 6065f37

Please sign in to comment.