Runtime: 56 ms C++ solution with 4 line


  • 0
    A
    class Solution {
    public:
        int firstUniqChar(string s) {
            int as[26] = {0}, i = 0;
            for(;i != s.size(); ++i) ++as[s[i] - 'a'];
            for(i = 0; i != s.size() && as[s[i] - 'a'] != 1; ++i);
            return (i == s.size()? -1: i);
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.