나의 sloution 은 아래와 같다.


class Solution {

public int solution(int N) { // write your code in Java SE 8 int binaryGap =0; int highestGap =0; String binary = Integer.toBinaryString(N); boolean meetOne = false; for(int i=0 ;i< binary.length();i++){ char index = binary.charAt(i); // System.out.println("#### index = "+index); if(index == '1'){ meetOne = true; if(binaryGap > highestGap){ highestGap = binaryGap; } binaryGap = 0; }else if(index == '0'){ if(meetOne){ binaryGap++; } } } return highestGap; } }


100% 이지만 코드는 좀 더 보완이 필요해 보인다.





'프로그래밍 > 알고리즘' 카테고리의 다른 글

시간 복잡도  (0) 2018.04.21
[Codility] CountSemiprimes  (0) 2018.04.21
[Codility] cyclicRotation  (0) 2018.04.15
[Codility] Stone wall  (0) 2018.04.15
알고리즘 공부 사이트  (0) 2017.01.27
블로그 이미지

낭만가을

,