Beautiful Binary String

  • + 0 comments

    Here are my C++ solution: int beautifulBinaryString(string b) { int i = 0, d = 0; while (i < b.length() - 2) { if (b[i] == '0' && b[i + 1] == '1' && b[i + 2] == '0') { d++; i += 3; // Skip to the character after "010" } else { i++; } } return d; }