读懂题意就出来了
class Solution { public int binaryGap(int N) { String s = Integer.toBinaryString(N); int ans = 0; int k = -1; int i = 0; while (s.charAt(i) == '0') i++; for (; i < s.length(); i++) { if (s.charAt(i) == '1') { k++; ans = Math.max(ans, k); k = 0; } else { k++; } } return ans; }}