Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ 1 - ๋‚ด์  (level.1)

๊ฐ์ž ๐Ÿฅ” 2021. 9. 8. 18:48
๋ฐ˜์‘ํ˜•

 

๋ฌธ์ œ๋งํฌ

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

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋‚ด์ 

๊ธธ์ด๊ฐ€ ๊ฐ™์€ ๋‘ 1์ฐจ์› ์ •์ˆ˜ ๋ฐฐ์—ด a, b๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. a์™€ b์˜ ๋‚ด์ ์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋•Œ, a์™€ b์˜ ๋‚ด์ ์€ a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] ์ž…๋‹ˆ๋‹ค. (n์€ a, b์˜

programmers.co.kr

 

๋‚˜์˜ ํ’€์ด

def solution(a, b):
    answer = 0
    for i in range(len(a)):
        answer += a[i]*b[i]
    return answer

 

๋‹ค๋ฅธ์‚ฌ๋žŒํ’€์ด

https://programmers.co.kr/learn/courses/30/lessons/70128/solution_groups?language=python3&type=all 

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

๊ฐ™์ด ์Šคํ„ฐ๋””ํ•˜๋Š” ์˜ค๋น ๋ž‘ ์ฝ”๋“œ ๋„์–ด์“ฐ๊ธฐ ํ•˜๋‚˜ ๋‹ค๋ฅด๊ณ  ๋‹ค๋˜‘๊ฐ™๋‹ค ใ…‹ใ…‹ใ…‹ใ…‹ ์—ญ์‹œ... ์‰ฌ์šด๋ฌธ์ œ๋Š” ์‚ฌ๋žŒ๋“ค ๋‹ค ์ƒ๊ฐํ•˜๋Š”๊ฒŒ ๋˜‘๊ฐ™๋‚˜๋ณด๋‹น

์ข‹์•„์š”๋ฅผ๊ฐ€์žฅ ๋งŽ์ด ๋ฐ›์€ ํ’€์ด๋Š” zip์„ ํ™œ์šฉํ•œ ๋ฐฉ๋ฒ•์ด์—ˆ๋‹ค. zip ์— ๋Œ€ํ•ด์„œ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋” ์—ฐ๊ตฌํ•ด๋ณด์•„์•ผ ๊ฒ ๋‹ค.

zip์„ ํ™œ์šฉํ•œ ํ’€์ด

def solution(a, b):
    answer = 0
    for i in range(len(a)):
        answer += a[i]*b[i]
    return answer

 

๋ฐ˜์‘ํ˜•