> For the complete documentation index, see [llms.txt](https://zhongquan789.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zhongquan789.gitbook.io/leetcode/lcof/mian-shi-ti-50.md).

# 面试题50

在字符串 s 中找出第一个只出现一次的字符。如果没有，返回一个单空格。

```
示例:

s = "abaccdeff"
返回 "b"

s = "" 
返回 " "
```

## 限制：

* 0 <= s 的长度 <= 50000

## Solutions

1. **straight forward**

```cpp
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 ' ';
    }
};
```
