2914. Minimum Number of Changes to Make Binary String Beautiful ## 思路 掃整個字串 並紀錄1,0的奇偶 如果目前字元是1/0 然後有奇數個0/1 就reset並且result+1 不然就更新1,0的奇偶 ## Code ```python class Solution: def minChanges(self, s: str) -> int: one = zero = 0 res = 0 for ch in s: if (ch == '1' and zero) or (ch == '0' and one): one = zero = 0 res += 1 elif ch == '1': one ^= 1 else: zero ^= 1 return res ``` -- ※ 發信站: 批踢踢實業坊(ptt-website.tw), 來自: 94.156.205.56 (臺灣) ※ 文章網址: https://ptt-website.tw/Marginalman/M.1730802190.A.D5C