Short C++ solution


  • 0
    K

    Here is my solution

    int countBinarySubstrings(string s) {
            int res = 0, n = s.length();
            for(int i = 0; i < n; i++){
                int l = i, r = i + 1;
                while(l >= 0 && r < n && ((s[l] - '0') ^ (s[r] - '0') == 1) && (s[l] == s[i])){
                    res++; l--; r++;
                }
            }
            return res;
        }
    

Log in to reply
 

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