Beautiful Binary String

  • + 0 comments

    Perl:

    sub beautifulBinaryString {
        my $b = shift;
        my $cnt = 0;
    
        while ($b =~ m/010/) {
            $b =~ s/010/011/;
            $cnt++;
        }
        return $cnt;
    }