https://programmers.co.kr/learn/courses/30/lessons/17681
"""
1. 아이디어
비트 연산자를 이용하는 쉬운 문제인거 같다.
2. 시간복잡도
O(N^2)
"""
def solution(n, arr1, arr2):
result = []
for i in range(n):
num = arr1[i] | arr2[i] # 차례대로 or연산을 해준다.
num = bin(num)[2:].zfill(n) # n의 숫자만큼 zfill함수로 채워준다.
res = ''
for i in num:
if i == '1':
res += '#'
else:
res += ' '
result.append(res)
return result
"""
1. 아이디어
replace함수를 이용해서 보기좋게 푼것 같다. bin함수의 리턴값은 str이므로
replace함수를 쓸 생각을 했으면 좋았을텐데 다음에는 아이디어를 떠올려야 겠다.
"""
def solution(n, arr1, arr2):
answer = []
for idx in range(n):
tmp = bin(arr1[idx] | arr2[idx])[2:].zfill(n)
tmp = tmp.replace('0', ' ')
tmp = tmp.replace('1', '#')
answer.append(tmp)
return answer
zfill()함수는 다시 한번 볼 필요가 있다.
zfill(width) 함수 사용
"2".zfill(3) -> "002"
"50000".zfill(5) -> "50000"
"123".zfill(5) -> "00123"