https://school.programmers.co.kr/learn/courses/30/lessons/17681
비트연산 문제
처음엔 Integer.toString(arr[i],2); 한다음 문자열 charAt()해서 각각 자리수에 따라 1이면 # 0이면 공백을 할라했는데
핵심은 비트연산이였다.
class Solution {
public String[] solution(int n, int[] arr1, int[] arr2) {
String[] code = new String[arr1.length];
for(int i = 0 ; i < arr1.length; i++){
code[i] = Integer.toString(arr1[i] | arr2[i],2);
String tmpbin = code[i];
code[i] = code[i].replace("1","#").replace("0"," ");
if( Integer.parseInt(tmpbin,2) < Math.pow(2,n - 1)){
do{
code[i] = " " + code[i];
}while(code[i].length() < n);
}
}
return code;
}
}
String.format을 사용할 생각을 못했다. 최대한 어떻게든 풀었다.