๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
4๏ธโƒฃ Python/Problem Solving

[Python Algorithm] ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ Programmers(Lv.2)

by seolhee2750 2022. 2. 4.
๋ฌธ์ œ

https://programmers.co.kr/learn/courses/30/lessons/12949

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ

[[2, 3, 2], [4, 2, 4], [3, 1, 4]] [[5, 4, 3], [2, 4, 1], [3, 1, 1]] [[22, 22, 11], [36, 28, 18], [29, 20, 14]]

programmers.co.kr

 

๋‚ด ๋ฌธ์ œ ํ’€์ด
def solution(arr1, arr2):
    answer = [[0]*len(arr2[0]) for _ in range(len(arr1))]
              
    for i in range(len(arr1)):
        for j in range(len(arr2[0])):
            for k in range(len(arr1[0])):
                answer[i][j] += arr1[i][k] * arr2[k][j]
    
    return answer

๐Ÿ‘‰ ๊ตฌํ˜„ ๋ฌธ์ œ๋กœ, 3์ค‘ for๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ answer 2์ฐจ์› ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋ฉด ๋œ๋‹ค.

 

๐Ÿ’ก ํ”ผ๋“œ๋ฐฑ
  • ๋‚œ ์ด ํ–‰๋ ฌ๊ณฑ ๋ฌธ์ œ๋Š” ํ’€ ๋•Œ๋งˆ๋‹ค for๋ฌธ ๋งŒ๋“œ๋Š”๊ฒŒ ํ—ท๊ฐˆ๋ฆฌ๋Š”๋ฐ,,
    ์™œ๊ทธ๋Ÿด๊นŒ

๋Œ“๊ธ€