int 解决方案(int N);即,给定一个正整数 N,返回其最长二进制间隙的长度。如果 N 不包含二进制间隙,该函数应返回 0。 例如,给定 N = 1041,该函数应返回 5,因为 N 的二进制表示形式为 10000010001,因此其最长的二进制间隙长度为 5。 publicintsolution(intn) {// write your code in Java SE 8String ...
class Solution { public int solution(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap. For example, given N = 1041 the function should return 5, because N has binary representation...
Write a function: class Solution { public int solution(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap. For example, given N = 1041 the function should return 5, because N has ...
class Solution { public int solution(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap. For example, given N = 1041 the function should return 5, because N has binary representation...
class Solution { public int solution(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap. For example, given N = 1041 the function should return 5, because N has binary representation...
class Solution { public int solution(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap. For example, given N = 1041 the function should return 5, because N has binary representation...
class Solution { public int solution(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap. For example, given N = 1041 the function should return 5, because N has binary representation...
class Solution { public int solution(int N); } that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap. For example, given N = 1041 the function should return 5, because N has binary representation...
Java class Solution { public int binaryGap(int N) { List<Integer> binary = new ArrayList<>(); int dis = 0; int preOneIndex = -1; while (N > 0) { binary.add(N & 0x01); N >>= 1; } for (int i = 0; i < binary.size();) { ...
Runtime:1 ms, faster than51.49%of Java online submissions for Binary Gap. Memory Usage:40.2 MB, less than76.36%of Java online submissions for Binary Gap. --- 求两个相近的1的距离,先找到第一个1的位置,然后从这里开始遍历, 如果找到1了, 就保留当前的距离的最大值, 然后继续遍历, 将pre的位置...