We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main.java.com.poogle.PG.Q77885; import java.util.Arrays; public class Solution { public static void main(String[] args) { long[] ans = solution(new long[]{2, 7}); System.out.println(Arrays.toString(ans)); } public static long[] solution(long[] numbers) { long[] answer = new long[numbers.length]; for (int i = 0; i < numbers.length; i++) { answer[i] = findClosest(numbers[i]); } return answer; } private static long findClosest(long number) { String origin = Long.toBinaryString(number); if (origin.charAt(origin.length() - 1) == '0') { return number + 1; } else { int i = 0; for (i = origin.length() - 1; i >= 0; i--) { if (origin.charAt(i) == '0') { break; } } String next; if (i == -1) { //모두 1인 경우 next = "10" + origin.substring(1); } else { //0이 하나라도 있는 경우 next = origin.substring(0, i) + "10" + origin.substring(i + 2); } return Long.parseLong(next, 2); } } }
The text was updated successfully, but these errors were encountered:
c1ec1d2
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: