Skip to content

Commit 6065f37

Browse files
authored
Create 884. Uncommon Words from Two Sentences (#587)
2 parents 1b4fea4 + 03b68bf commit 6065f37

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
vector<string> uncommonFromSentences(string s1, string s2) {
4+
string s = s1+ " "+ s2+ " ";
5+
// cout<< s<< endl;
6+
unordered_map<string, int>mpp;
7+
8+
string temp = "";
9+
for(int i = 0; i < s.size(); i++){
10+
if(s[i] == ' '){
11+
cout<<temp<< endl;
12+
mpp[temp]++;
13+
temp = "";
14+
}
15+
else
16+
temp+=s[i];
17+
}
18+
vector<string>ans;
19+
for (auto it :mpp) {
20+
if(it.second == 1)
21+
ans.push_back(it.first);
22+
}
23+
return ans;
24+
}
25+
};

0 commit comments

Comments
 (0)