Loading... ###### 136. Single Number ![136](https://mioe-xyz.oss-cn-shanghai.aliyuncs.com/usr/uploads/2022/11/4226140631.png) * 交换律:a ^ b ^ c <=> a ^ c ^ b * 任何数于0异或为任何数 0 ^ n => n * 相同的数异或为0: n ^ n => 0 `var a = [2, 3, 2, 4, 4]` `2 ^ 3 ^ 2 ^ 4 ^ 4 等价于 2 ^ 2 ^ 4 ^ 4 ^ 3 => 0 ^ 0 ^3 => 3` ###### 1758. Minimum Changes To Make Alternating Binary String ![1758](https://mioe-xyz.oss-cn-shanghai.aliyuncs.com/usr/uploads/2022/11/2630183447.png) ```c++ // 1 & 1 = 1 // 1 & 0 = 0 // 0 & 0 = 0 int minOperations(string s) { char a[2] = {'0', '1'}; int ans = 0, t = 0; for(int i = 0; i < s.size(); i++) { if(a[i & 1] == s[i]) ans++; else t++; } return min(ans, t); } ``` Last modification:November 29, 2022 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed