Beautiful Binary String

  • + 0 comments

    // c#

    public static int beautifulBinaryString(string b)
    {       
        string newB = b.Replace("010", "xxx");
        int occur = 0;
    
        for(int i=0; i<newB.Length; i++)
        {
            if (newB.Substring(i,1) == "x")
            {
                i += 2;
                occur++;
            }
        }
    
        return occur;
    }