classSolution{public:intminOperations(strings){intcost10;// the cost to make s "1010"for(inti=0;i<s.length();++i)if(s[i]-'0'==i%2)++cost10;constintcost01=s.length()-cost10;// the cost to make s "0101"returnmin(cost10,cost01);}};
1 2 3 4 5 6 7 8 9101112
classSolution{publicintminOperations(Strings){intcost10=0;// the cost to make s "1010"for(inti=0;i<s.length();++i)if(s.charAt(i)-'0'==i%2)++cost10;finalintcost01=s.length()-cost10;// the cost to make s "0101"returnMath.min(cost10,cost01);}}
1234567
classSolution:defminOperations(self,s:str)->int:# the cost to make s "1010"cost10=sum(int(c)==i%2fori,cinenumerate(s))# the cost to make s "0101"cost01=len(s)-cost10returnmin(cost10,cost01)