๋น„๋ฐ€์ง€๋„ - ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

๋ฌธ์ œ

๋น„๋ฐ€์ง€๋„

ํ•ด์„ค

  • ์ฒ˜์Œ์— ํ’€์—ˆ์„ ๋•Œ๋Š” ์ด์ค‘ for๋ฌธ์ด๋ž‘ if๋ฌธ์œผ๋กœ ๋ฌธ์ž์—ด์„ ์ผ์ผํžˆ ๋ถ„๋ฆฌํ–ˆ์—ˆ๋‹ค.
  • ๋‹ค๋ฅธ ์ข‹์€ ํ’€์ด์—์„œ๋Š” ๋น„ํŠธ ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•ด์„œ ํ•ด๊ฒฐํ–ˆ๋‹ค.
  • 2๊ฐœ์˜ for๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹  for in zip์„ ์‚ฌ์šฉํ•˜๋ฉด ๋” ๊น”๋”ํ•˜๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋น„ํŠธ ์—ฐ์‚ฐ์ž, zfill, replace, zip ํ•จ์ˆ˜์— ๋Œ€ํ•ด์„œ ๋ฐฐ์šธ ์ˆ˜ ์žˆ๋Š” ์ข‹์€ ๋ฌธ์ œ์ด๋‹ค.

ํ’€์ด 1

def solution(n, arr1, arr2):
    result = []
    for i in range(n):
        result.append(bin(arr1[i]|arr2[i])[2:]
                      .zfill(n)
                      .replace('1', "#")
                      .replace('0', " "))
    return result

ํ’€์ด 2

def solution(n, arr1, arr2):
    answer = []
    for i,j in zip(arr1,arr2):
        a12 = str(bin(i|j)[2:])
        .rjust(n,'0')
        .replace('1','#')
        .replace('0',' ')
        answer.append(a12)
    return answer