Skip to content

Commit

Permalink
Ajustes de código.
Browse files Browse the repository at this point in the history
  • Loading branch information
wegneto committed Aug 16, 2016
1 parent dd43f57 commit 98b1fde
Showing 1 changed file with 8 additions and 17 deletions.
Expand Up @@ -3,37 +3,28 @@
public class BinaryGap {

public int solution(int N) {
String binary = "";
while (N >= 1) {
int resto = (N % 2);
N = N / 2;
binary = resto + binary;
}

binary = (binary.isEmpty() ? "00" : binary);

System.out.println(binary);
int found = 0;
String binary = Integer.toBinaryString(N);

int max = 0;
int aux = 0;

for (int i = 0; i < binary.length(); i++) {
if (binary.charAt(i) == '0') {
aux++;
} else if (aux > 0) {
if (aux > found) {
found = aux;
if (aux > max) {
max = aux;
}
aux = 0;
}

}
System.out.println(found);

return found;
return max;
}

public static void main(String[] args) {
new BinaryGap().solution(35);
new BinaryGap().solution(1047);
}

}

0 comments on commit 98b1fde

Please sign in to comment.