๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Kotlin/Programmers Algorithm

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์ฝ”ํ‹€๋ฆฐ] ๋‚ด์  #70128 (dot product)

by eun.24k 2023. 10. 31.

#70128

๐ŸŽ„ Question ?

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

class Solution {
    fun solution(a: IntArray, b: IntArray): Int {
        var answer: Int = 1234567890
        return answer
    }
}

๐Ÿงฉ Thought Process

  1. ์ธ๋ฑ์Šค๊ฐ€ ๊ฐ™์€ ๋‘ ๋ฐฐ์—ด์„ ๊ณฑํ•œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ
  2. ์ƒˆ๋กœ ๋งŒ๋“ค ๋ฐฐ์—ด์˜ sum() ๊ตฌํ•˜๊ธฐ

 

๐ŸŽ€ Answer

class Solution {
    fun solution(a: IntArray, b: IntArray): Int {
        var answer = 0
        for (i in 0 until a.size) {
            answer += a[i]*b[i]
        }
        return answer
    }
}

 

๐ŸŽ Result

 

 

๐Ÿ† Comment

๋ฟ… ! ์›์ƒท์›ํ‚ฌ~