Beautiful Binary String

  • + 0 comments

    My answer with Typescript, simple

    function beautifulBinaryString(b: string): number {
        /**
         * replace and counting until [b] doesn't include '010' any more
         */
        let count = 0
    
        while (b.includes('010')) {
            b = b.replace('010', '011')
            count++
        }
    
        return count;
    }