面试题50
示例:
s = "abaccdeff"
返回 "b"
s = ""
返回 " "限制:
Solutions
class Solution {
public:
char firstUniqChar(string s) {
// remember to initialize, otherwise values are undefined.
int counter[128] = {0};
for (auto & c : s)
counter[c]++;
for (auto & c : s)
if (counter[c] == 1)
return c;
return ' ';
}
};Last updated