aboutsummaryrefslogtreecommitdiff
path: root/min_num_change_binary_str.py
blob: 20c4cf0de0ffbdfd6a9fe98f6ecfbf992a755f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 2914. Minimum Number of Changes to Make Binary String Beautiful

"""
you are given a 0-indexed binary string 's' having an even length. a string
is beautiful if it's possible to partition it into one or more substrings
such that each substring has an even length and each substring contains only
1's or only 0's. you can change any character in 's' to a 0 or 1. return the
minimum number of changes required to make the string 's' beautiful.
"""


class Solution(object):
    def minChanges(self, s):
        """
        :type s: str
        :rtype: int
        """
        n, changes = len(s), 0
        for i in range(0, n, 2):
            if s[i] != s[i + 1]:
                changes += 1
        return changes


if __name__ == "__main__":
    obj = Solution()
    print(obj.minChanges(s="1001"))
    print(obj.minChanges(s="10"))
    print(obj.minChanges(s="0000"))