ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • BinaryGap
    Study/알고리즘 2018. 1. 11. 13:47

    문제요약 / 결과 73점


    N이라는 숫자 입력시 2진수 변환시 

    1과 1사이의 0의 갯수 최대값을 구하라


    2진수를 구하는법을 몰라서 생짜로 짯더니... ;; 


    멍청하지만 대단하다.




        public static String twoDigits(int n ){
            int mok = n;
            String twoDigit = "";
    
            while(true){
                twoDigit += mok % 2 + "";
                mok = mok / 2;
                if(mok < 2){
                    twoDigit += mok + "";
                    break;
                }
            }
    
            char[] reverse = twoDigit.toCharArray();
            String temp = "";
            for(int i = reverse.length - 1 ; i >= 0 ; i--){
                temp += reverse[i];
            }
    
            return temp;
        }
    
        public static int solution(int n){
            String twoDigits = twoDigits(n);
            char array[] = twoDigits.toCharArray();
    
            int count = 0;
            int maxCount = 0;
            for(int i = 0 ; i < array.length ; i++){
                if(array[i] == '1'){
                    count = 0;
                }else{
                    count++;
                    if(count > maxCount){
                        maxCount = count;
                    }
                }
            }
            return maxCount;
        }
    


    'Study > 알고리즘' 카테고리의 다른 글

    PassingCars  (0) 2018.01.12
    CountDiv  (0) 2018.01.12
    MaxCounters  (0) 2018.01.12
    MissingInteger  (0) 2018.01.12
    FrogRiverOne  (0) 2018.01.12
    PermCheck  (0) 2018.01.11
    PermMissingElem  (0) 2018.01.11
    FrogJmp  (0) 2018.01.11
    CyclicRotation  (0) 2018.01.11
    OddOccurrencesInArray  (0) 2018.01.11

    댓글

COPYRIGHT 2010 EpoNg. ALL RIGHTS RESERVED.