From 3d1063f6b592d3aab8bd32ba8fbaf40a8b4da906 Mon Sep 17 00:00:00 2001 From: wlsgud Date: Wed, 8 Jul 2020 20:22:22 +0900 Subject: [PATCH] =?UTF-8?q?1-3=20=EB=8B=A4=EC=9D=8C=20=ED=81=B0=20?= =?UTF-8?q?=EC=88=AB=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Solution.java" | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) 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)); + // } }