summaryrefslogtreecommitdiff
path: root/top-interview-questions/easy/strings/03_first_unique_character.cc
blob: 871f761c76760faea3b628da21da5c37b3f9aec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public:
    int firstUniqChar(string s) {
        int count[256] = {};

        for (char c : s) {
            count[c]++;
        }

        for (size_t i = 0; i < s.size(); ++i) {
            if (count[s[i]] == 1) {
                return i;
            }
        }

        return -1;
    }
};