oha, Runtime: 948 ms C++ solution


  • 0
    A
    class Solution {
    public:
        int firstUniqChar(string s) {
            int index = -1;
            const unsigned long len = s.size();
            vector<bool> bs(len);
        
            for (int i = 0; i != len;  ++i) {
                 bool fbs = false;
                 if (bs[i]) {
                      continue;
                }
                 for (int j = i; j != len; ++j) {
                    // if i == j ,then go the next element;
                    if (i == j || bs[j]) {
                        continue;
                    }
                    if (s[i] == s[j]) {
                        bs[i] = bs[j] = true;
                        fbs = true;
                    }
                }
                if (fbs == false) {
                    index = i;
                    break;
                }
            }
        return index;
        }
    };
    

Log in to reply
 

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