Beautiful Binary String

  • + 0 comments

    Simple C Solution

    int beautifulBinaryString(char* b) {
        int count = 0;
        int length = strlen(b);
        
        for (int i = 0; i <= length - 3; i++) {
            // Check for the substring "010"
            if (b[i] == '0' && b[i + 1] == '1' && b[i + 2] == '0') {
                count++;
                // Skip the next two characters to avoid overlapping
                i += 2; 
            }
        }
        
        return count;
    }