Skip to content

Commit 724aff7

Browse files
committed
feat: add cpp solution to lcof problem: No.50
1 parent 2f00995 commit 724aff7

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lcof/面试题50. 第一个只出现一次的字符/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ var firstUniqChar = function (s) {
8383
};
8484
```
8585

86+
### **C++**
87+
88+
```cpp
89+
class Solution {
90+
public:
91+
char firstUniqChar(string s) {
92+
unordered_map<char, bool> um;
93+
for (char c : s) {
94+
um[c] = um.find(c) == um.end();
95+
}
96+
for (char c : s) {
97+
if (um[c]) {
98+
return c;
99+
}
100+
}
101+
return ' ';
102+
}
103+
};
104+
```
105+
86106
### **...**
87107
88108
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
char firstUniqChar(string s) {
4+
unordered_map<char, bool> um;
5+
for (char c : s) {
6+
um[c] = um.find(c) == um.end();
7+
}
8+
for (char c : s) {
9+
if (um[c]) {
10+
return c;
11+
}
12+
}
13+
return ' ';
14+
}
15+
};

0 commit comments

Comments
 (0)