交错01串

交错01串

http://www.nowcoder.com/questionTerminal/3fbd8fe929ea4eb3a254c0ed34ac993a

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char[] ch = str.toCharArray();
        int a = 1; int temp = 1;
        for (int i=0;i<ch.length-1;i++){
            if(ch[i]!= ch[i+1]){
                a++;
            }else {
                if(temp<=a){
                    temp = a;
                    a=1;
                }
            }
        }
        System.out.println(temp>a?temp:a);
    }
}
全部评论

相关推荐

积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务