pocky nè

 avatar
unknown
c_cpp
a year ago
462 B
8
Indexable
class Solution {
public:
    int firstUniqChar(string s) {
        //a = 97, z = 122
        int appear[125];

        int res = -1; //kết quả trả về

        for (int i = 0; i < s.length(); i++) {
            appear[(int)s[i]]++;
        }

        for (int i = 0; i < s.length(); i++)
            if (appear[(int)s[i]] == 1) 
            {
                res = i;
                break;
            }

        return res;
    }
};
Leave a Comment