题目描述
贪心
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//贪心思路:集合思想,相邻两个匹配还是不匹配,发现匹配比不匹配可以出现最优解,四种情况:11、00、1?、0?、?1、?0
String n = scanner.nextLine();
char []a = n.toCharArray();
int res = 0;
for (int i = 0; i+1 < n.length(); i++) {
if(a[i]==a[i+1]||a[i]=='?'||a[i+1]=='?'){
res++;
i++;
}
}
System.out.println(res);
scanner.close();
}
}