일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 코틀린
- 다시봐
- 알고리즘 인증_1주차
- foldindexed
- 알고리즘 인증
- filternot
- recyclerview
- 취준기록
- array랑 list
- 알고리즘 인증_2주차
- Filter
- 다시 정리해야함
- 코딩테스트
- iPortfolio
- 다시정리하기
Archives
- Today
- Total
Moments of growth
[Lv1 Kotlin] 음양 더하기 본문
[내 코드]
class Solution {
fun solution(absolutes: IntArray, signs: BooleanArray): Int {
var answer: Int = 0
for(i in 0 until signs.size){
if(signs[i] == true){
answer += absolutes[i]
}else answer -= absolutes[i]
}
return answer
}
}
[다른 사람 풀이]
class Solution {
fun solution(absolutes: IntArray, signs: BooleanArray) =
absolutes.foldIndexed(0) { idx, acc, num -> acc + if (signs[idx]) num else -num }
}
Comments