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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์ฝ”ํ‹€๋ฆฐ] ์•ฝ์ˆ˜์˜ ํ•ฉ #12928

by eun.24k 2023. 10. 20.

#12928

๐ŸŽ„ Question ?

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

// given
class Solution {
    fun solution(n: Int): Int {
        var answer = 0
        return answer
    }
}

 

๐Ÿงฉ Thought Process

  1. ์ •์ˆ˜ n๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ํ™•์ธ.
  2. ๋‚˜๋ˆ„์–ด๋ณด๊ณ  ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋ฉด ์•ฝ์ˆ˜์ž„์œผ๋กœ answer์— ์ˆ˜ ๋”ํ•˜๊ธฐ

 

๐ŸŽ€ Answer

class Solution {
    fun solution(n: Int): Int {
        var answer = 0
        for (i in 1 until n+1) {
            if(n%i == 0) {
                answer += i
            }
        }
        return answer
    }
}

 

๐ŸŽ Result

<์ถœ๋ ฅ๊ฐ’>

 

๐Ÿ† Comment

์ „์— ๋ฌธ์ œ๊ฐ€ ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ ค์„œ ์‚ฌ๊ธฐ๊ฐ€ ๋–จ์–ด์กŒ๋Š”๋ฐ.. ๋–จ์–ด์ง„ ์ž์‹ ๊ฐ์„ ์˜ฌ๋ ค์ฃผ๋Š” ๊ทธ๋Ÿฐ ๋ฌธ์ œ์˜€๋˜ ๊ฑฐ ๊ฐ™๋‹น.