class Solution {
fun solution(l: Int, r: Int): IntArray {
return (l..r)
.filter{ it.toString().all(){ it == '0' || it == '5'}}
.ifEmpty{listOf(-1)}
.toIntArray()
}
}
class Solution {
fun solution(l: Int, r: Int): List<Int> {
return (l..r).filter { it.toString()
.all { ch -> ch == '0' || ch == '5' }
}.takeIf(List<Int>::isNotEmpty) ?: listOf(-1)
}
}
all
함수는 "554"라는 문자열을 각 문자에 대해 조건을 체크합니다.it == '0' || it == '5'
에서 '5' == '5'가 참입니다.it == '0' || it == '5'
에서 '5' == '5'가 참입니다.it == '0' || it == '5'
에서 '4' == '0' || '4' == '5'가 거짓입니다.세 번째 문자 '4'가 조건을 만족하지 않기 때문에, all 함수는 즉시 false를 반환하고 더 이상 검사하지 않습니다.