diff --git "a/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" "b/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" index 07debf4..aa698e7 100644 --- "a/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" +++ "b/week1/3. \353\213\244\354\235\214 \355\201\260 \354\210\253\354\236\220/Solution.java" @@ -4,8 +4,47 @@ */ class Solution { + public static void main(String[] args) { + + Solution sol = new Solution(); + + System.out.println(sol.solution(78)); + + } + public int solution(int n) { - int answer = 0; - return answer; + + int countOfOne = countOne(n); + + while (countOfOne != countOne(++n)) { + + } + + return n; + } + + public int countOne(int n) { + int count = 0; + + String binary = Integer.toBinaryString(n); + + for (String number : binary.split("")) { + if (number.equals("1")) { + count++; + } + } + + return count; } + + + //문제 풀이를 보는데 거기에서 더 이런식으로도 줄일수 있구나 하면서 보고 있어요 형.. 신기하네요 + // public int nextBigNumber(int n) { + // int postPattern = n & -n, smallPattern = ((n ^ (n + postPattern)) / postPattern) >> 2; + // return n + postPattern | smallPattern; + // } + // public static void main(String[] args) { + // int n = 78; + // System.out.println(new TryHelloWorld().nextBigNumber(n)); + // } }