Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // you can also use imports, for example:
- // import java.util.*;
- // you can write to stdout for debugging purposes, e.g.
- // System.out.println("this is a debug message");
- class Solution {
- public int solution(int N) {
- String binary = Integer.toBinaryString(N);
- int maxgap = 0;
- boolean start = false;
- int gap = 0;
- for(char h : binary.toCharArray()) {
- if (h == '1') {
- if(!start) {
- start = true;
- }
- else if(gap > 0) {
- if(gap > maxgap) maxgap = gap;
- gap = 0;
- }
- continue;
- }
- if(start)
- {
- gap++;
- }
- }
- return maxgap;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement