Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions yerim-son/pg_181931.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 등차수열의 특정한 항만 더하기

class Solution {
fun solution(a: Int, d: Int, included: BooleanArray): Int {
var answer: Int = 0

for (i in 0 until included.size) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

included의 bool값을 x라고 하고, 인덱스는 그대로 index라고 할게요.
이때 반복문을 저는 for((index, x) in included.withIndex()) 형태로 인덱스와 리스트의 값이 모두 필요할때 사용하는데 좋더라구요.

if (included[i]) {
answer += a + d * i
}
}

return answer
}
}