[프로그래머스] 연속 부분 수열 합의 개수(Kotlin)
풀이
import java.util.*
class Solution {
fun solution(elements: IntArray): Int {
var elementsCircle = arrayOf<Int>()
for(e in elements) elementsCircle += e
for(e in elements) elementsCircle += e
val sumNum = mutableSetOf<Int>()
var sum = 0
for(e in elements) sum += e
sumNum.add(sum)
for(len in 1 until elements.size){
for(start in 0 until elements.size){
var sum = 0
sum += elementsCircle[start]
for(next in start+1 until start+len) sum += elementsCircle[next]
sumNum.add(sum)
}
}
var answer: Int = sumNum.size
return answer
}
}