hết dỗi nha :3

mail@pastecode.io avatar
unknown
c_cpp
17 days ago
462 B
6
Indexable
Never
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