다음 큰 숫자

JJW·2024년 12월 13일

코딩 테스트

목록 보기
9/23

문제


문제 풀이

using System;

class Solution 
{
    public int solution(int n) 
    {
        int curCount = CountOnes(n);
        
        int nextCount = n + 1;

        while(true)
        {
            if(CountOnes(nextCount) == curCount)
                return nextCount;
            
            nextCount++;
        }
    }
    
    public int CountOnes(int n)
    {
        return Convert.ToString(n,2).Split('1').Length - 1;
    }
}

느낀 점

생각보다 쉬운 문제였습니다..

profile
Unity 게임 개발자를 준비하는 취업준비생입니다..

0개의 댓글