public class CountConformingBitmasks_230128 {
public static void main(String[] args) {
int A = 1073741727;
int B = 1073741631;
int C = 1073741679;
System.out.println(solution(A,B,C));
}
public static int solution(int A, int B, int C) {
int answer = 0;
String aStr = Integer.toBinaryString(A);
String bStr = Integer.toBinaryString(B);
String cStr = Integer.toBinaryString(C);
answer = checkBit(aStr)+ checkBit(bStr)+ checkBit(cStr);
answer -= checkBit(Integer.toBinaryString(A|B));
answer -= checkBit(Integer.toBinaryString(A|C));
answer -= checkBit(Integer.toBinaryString(B|C));
answer += checkBit(Integer.toBinaryString(A|B|C));
return answer;
}
private static int checkBit(String number){
int count=0;
for (int i = 0; i < number.length(); i++) {
if(number.charAt(i)=='0'){
count++;
}
}
count += 30 - number.length();//★
return (int)Math.pow(2, count);
}
}
시간 복잡도 관계로 도움 받음!
루프를 돌려버리고 싶은데 퍼포먼스 문제 나는 코드를 짜고... 깨달음을 얻음
-.-)b
댓글
댓글 쓰기