{"id":426355,"date":"2021-04-05T11:18:14","date_gmt":"2021-04-05T03:18:14","guid":{"rendered":"http:\/\/4563.org\/?p=426355"},"modified":"2021-04-05T11:18:14","modified_gmt":"2021-04-05T03:18:14","slug":"leetcode-1758","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=426355","title":{"rendered":"leetcode 1758"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  leetcode 1758               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yujianwjj <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>https:\/\/leetcode.com\/problems\/minimum-changes-to-make-alternating-binary-string\/<\/p>\n<p>\u9898\u76ee\u6bd4\u8f83\u7b80\u5355\uff0c\u53ea\u6709 010101&#8230; \u6216\u8005 101010&#8230; \u4e24\u4e2a\u65b9\u6848 \u6700\u5f00\u59cb\u6211\u7684\u89e3\u6cd5\u662f\uff1a<\/p>\n<pre><code>func minOperations(s string) int {     count1 := 0     \/\/ 010101...     for i := 0; i &lt; len(s); i++ {         if int(s[i] - '0') != i % 2 {             count1++         }     }     count2 := 0     \/\/ 10101010...     for i := 0; i &lt; len(s); i++ {         if int(s[i] - '0') != (i+1) % 2 {             count2++         }     }     return min(count1, count2) } <\/code><\/pre>\n<p>\u540e\u6765\u53d1\u73b0\u66f4\u7b80\u5355\u4e00\u70b9\u7684<\/p>\n<pre><code>func minOperations(s string) int {     count1 := 0     \/\/ 010101...     for i := 0; i &lt; len(s); i++ {         if int(s[i] - '0') != i % 2 {             count1++         }     }          return min(count1, len(s)-count1) } <\/code><\/pre>\n<p>\u6211\u7684\u7591\u95ee\u662f\u5982\u4f55\u7528\u6570\u5b66\u8bc1\u660e\u8fd9\u4e24\u79cd\u65b9\u6848\u52a0\u8d77\u6765\u521a\u597d\u662f s \u7684\u957f\u5ea6\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5722436\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : misdake <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c S ^ A = 010101&#8230;<br \/>\u90a3 S ^ ~A = 101010&#8230;<br \/>A \u548c~A \u4e92\u8865\uff0c\u4e24\u4e2a\u6570\u4e2d 1 \u7684\u6570\u91cf\u603b\u548c\u5c31\u662f\u957f\u5ea6\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>leetcode 1758 \u8cc7\u6df1\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/426355"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=426355"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/426355\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426355"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}