牛客网真题-94-最长区间
最长区间
http://www.nowcoder.com/questionTerminal/43077cbb88024b2188de64a471352b8e
import java.util.Scanner; public class Main { public static void main(String[] args){ String s = new Scanner(System.in).nextLine(); s = s + s; int p = 0, q = 0, cnt = 0; while (p < s.length()) { if(s.charAt(p) == '1'){ q = p; while (q < s.length() && s.charAt(q) == '1') { q++; } cnt = Math.max(cnt, q - p); p = q; }else{ p++; } } System.out.println(Math.min(cnt, s.length() / 2)); } }