일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Filter
- recyclerview
- array랑 list
- filternot
- 코딩테스트
- 코틀린
- 알고리즘 인증
- iPortfolio
- 취준기록
- 다시 정리해야함
- foldindexed
- 알고리즘 인증_1주차
- 다시정리하기
- 다시봐
- 알고리즘 인증_2주차
Archives
- Today
- Total
목록foldindexed (1)
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 } }
카테고리 없음
2022. 9. 18. 13:49