#12912
๐ Question ?
https://school.programmers.co.kr/learn/courses/30/lessons/12912
class Solution {
fun solution(a: Int, b: Int): Long {
var answer: Long = 0
return answer
}
}
๐งฉ Thought Process
- 3์์ 5๊น์ง for ๋ฌธ ์ฌ์ฉ
- answer์ for๋ฌธ์ ๋ค์ด๊ฐ๋ ์ธ๋ฑ์ค ๊ฐ์ ์์ฐจ์ ์ผ๋ก ๋ํ๊ธฐ
- a ๊ฐ b ๋ณด๋ค ํด๋๋ b๊ฐ a ๋ณด๋ค ํด ๋๋ก ๊ฒฝ์ฐ ๋๋๊ธฐ
๐ Answer
class Solution {
fun solution(a: Int, b: Int): Long {
var answer: Long = 0
if (a <= b) {
for (i in a..b) {
answer += i
}
} else if (a > b) {
for (i in b..a) {
answer += i
}
}
return answer
}
}
๐ Result
๐ Comment
๊น๋. ์ค๊ฐ์ค๊ฐ์ ์๋ ์ฌ์ด ๋ฌธ์ ๋ค์ด ์ฌ๋ง์์ ๋ฐ๊ฒฌํ ์ค์์์ค ๊ฐ๋น ํํ