일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- cpp
- mpnp
- LV1
- 선형대수
- 위니펙
- machine learning
- 알고리즘
- 프로그래머스
- 코딩테스트
- Deep learning
- 온라인석사
- 컴퓨터과학과
- 캐나다 영주권
- 개발자
- zeros
- leetcode
- Plotting
- omscs
- 조지아텍
- LAA
- 방송통신대학교
- C++
- 딥러닝
- 매트랩
- 주정부이민
- 방통대
- MATLAB
- 기본
- 머신러닝
- EOI
Archives
- Today
- Total
Byte by Byte
884. Uncommon Words from Two Sentences.cpp 본문


class Solution {
public:
vector<string> uncommonFromSentences(string s1, string s2) {
vector<string>res;
map<string,int>m;
for(int i =0; i<s1.size();i++){
string tmp ="";
while(1){
if(s1[i]==' ' || i == s1.size()) break;
tmp+=s1[i];
i++;
}
// cout<< tmp <<endl;
m[tmp]++;
if(s1[i]==' ')continue;
}
for(int i =0; i<s2.size();i++){
string tmp ="";
while(1){
if(s2[i]==' ' || i == s2.size()) break;
tmp+=s2[i];
i++;
}
//cout<< tmp <<endl;
m[tmp]++;
if(s2[i]==' ') continue;
}
for(auto x : m){
//cout<< x.second<< " "<< x.first <<endl;
if(x.second ==1)
res.push_back(x.first);
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1694. Reformat Phone Number.cpp (0) | 2021.12.15 |
---|---|
575. Distribute Candies.cpp (0) | 2021.12.15 |
46. Permutations.cpp (0) | 2021.12.14 |
118. Pascal's Triangle.cpp (0) | 2021.12.13 |
2. Add Two Numbers.cpp (0) | 2021.11.26 |