ARST打卡第143周[143/521]

Algorithm

lc884_两句话中的不常见单词

思路: 分隔出单词,然后计算两个串中,单词的总出现次数,把出现次数为一的返回

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
31
32
33
34
35
36
37
38
39
40
class Solution {
unordered_map<string, int> m_word_count;
public:
void splitStr2Word(string s) {
int sz = s.size();
int i = 0;
string tmp;

while (i < sz && s[i] == ' ') {
i++;
}

for (; i < sz; i++) {
if (s[i] == ' ') {
m_word_count[tmp]++;
tmp.clear();
}
else {
tmp += s[i];
}
}

if (s[sz - 1] != ' ') {
m_word_count[tmp]++;
tmp = ' ';
}
}

vector<string> uncommonFromSentences(string s1, string s2) {
vector<string> ans;
splitStr2Word(s1);
splitStr2Word(s2);
for (auto x : m_word_count) {
if (x.second == 1) {
ans.push_back(x.first);
}
}
return ans;
}
};

Review

TED_没人知道我的思想如何重生

悲剧不可避免,但只要还活着,我们可能就有机会新生,活着才有希望

Tips

UNIX的五种IO模型

Share

windows10安装双系统后,删除linux,开机进入grub怎么办