Re: [閒聊] 每日leetcode

作者: devilkool (對貓毛過敏的貓控)   2024-11-06 00:50:09
2914. Minimum Number of Changes to Make Binary String Beautiful
字串s長度必為偶數,只有binary 0或1
要讓字串可以切分成每個子字串都是偶數且為同樣的數字
需要將字元變換多少次
思路:檢查兩兩一組是否一樣就好
public int MinChanges(string s)
{
var changeCount = 0;
for (int i=0;i<s.Length;i+=2)
{
if (s[i] != s[i+1])
{
changeCount++;
}
}
return changeCount;
}

Links booklink

Contact Us: admin [ a t ] ucptt.com