Posted on

Description

Submission

class Solution {
    int freq[26];
public:
    int firstUniqChar(string s) {
        for(char ch: s) {
            ++freq[ch-'a'];
        }

        for(int i = 0; i < s.length(); ++i) {
            if(freq[s[i]-'a'] == 1) return i;
        }

        return -1;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *