Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions week1/3. 다음 큰 숫자/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 처음에 이렇게 구현했습니다!

int count = 0;

String binary = Integer.toBinaryString(n);

for (String number : binary.split("")) {
if (number.equals("1")) {
count++;
}
}

return count;
}


//문제 풀이를 보는데 거기에서 더 이런식으로도 줄일수 있구나 하면서 보고 있어요 형.. 신기하네요
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거는 진짜 이해하기 어려운거 같습니다. 비트연산자 한두개도 어려운데 몇개여 이게..
숏코딩이 멋지고 화려하 지만 저는 이런 코드는 아예 염두해 두지 않으려합니다 ㅎㅎ.

// 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));
// }
}