๊ธ€ ์ž‘์„ฑ์ž: ํƒ์‹œ ์šด์ „์‚ฌ
๋ฐ˜์‘ํ˜•

๐Ÿ—บ ๋น„๋ฐ€์ง€๋„ ๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ


๐Ÿ˜ƒ ๋‚˜์˜ ์ฝ”๋“œ

def solution(n, arr1, arr2):
    answer = []
    for decimal1, decimal2 in zip(arr1, arr2):
        binary12 = str(bin(decimal1 | decimal2))[2:]
        binary12 = '0' * (n - len(binary12)) + binary12
        binary12 = binary12.replace('1', '#')
        binary12 = binary12.replace('0', ' ')
        answer.append(binary12)
    return answer

๋น„ํŠธ์—ฐ์‚ฐ(Bitwise Operation)์„ ์ด์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ๋ฌธ์ œ ์ค‘๊ฐ„์— ๋‘˜ ์ค‘ ํ•˜๋‚˜๊ฐ€๋ผ๋Š” ๋ง์ด ํžŒํŠธ๊ฐ€ ๋  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”. ํ’€์ด ๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋‘ ์ง€๋„์˜ ๋ฐฐ์—ด์„ zip์„ ์ด์šฉํ•˜์—ฌ ๊ฐ๊ฐ์˜ ๋ฐฐ์—ด์—์„œ ์›์†Œ๋ฅผ ํ•˜๋‚˜์”ฉ ๊บผ๋ƒ…๋‹ˆ๋‹ค. ์ด์ œ ์ด 10์ง„ ๋ฐ์ดํ„ฐ๋ฅผ OR๋กœ ๋น„ํŠธ ์—ฐ์‚ฐํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์ง€๋„์˜ ๋ฐ์ดํ„ฐ๋Š” 10์ง„๋ฒ•์œผ๋กœ ์•”ํ˜ธํ™” ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ 2์ง„๋ฒ•์œผ๋กœ ๋ฐ”๊พธ๋Š” ๋ฐ ์—ฌ๊ธฐ์„œ๋Š” bin()์„ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค. bin()์„ ์ด์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์•ž์— 0b๋ผ๋Š” ๋ฌธ์ž๊ฐ€ ์ถ”๊ฐ€๋กœ ๋ถ™์Šต๋‹ˆ๋‹ค ๋”ฐ๋ผ์„œ ์ ์ ˆํ•˜๊ฒŒ ๋ฌธ์ž์—ด์„ ์ž˜๋ผ์ค๋‹ˆ๋‹ค. ์ด์ง„ ๋ฐ์ดํ„ฐ์˜ ๊ธธ์ด๊ฐ€ ์ง€๋„์˜ ํ•œ ๋ณ€์˜ ๊ธธ์ด์™€ ๊ฐ™์•„์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ „์ฒด ๊ธธ์ด๊ฐ€ n์ด ๋˜๋„๋ก ์•ž์— 0์„ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค. ์ด์ œ ์ด ์ด์ง„๋ฒ•์œผ๋กœ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ถœ๋ ฅ ํ˜•ํƒœ์— ๋งž๊ฒŒ ๋ฌธ์ž์—ด์˜ replace() Method๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณ€ํ™˜ํ•œ ๋’ค ๊ฐ๊ฐ answer๋ฐฐ์—ด์— append()ํ•ด์ฃผ๋ฉด ๋ฌธ์ œ๊ฐ€ ๋งˆ๋ฌด๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

Written with StackEdit.


๋ฐ˜์‘ํ˜•