Notice
Recent Posts
Recent Comments
Link
- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- blog
- jlpt
- pullrequest
- 안드로이드
- errorhandling
- n3문법
- CustomTab
- 진짜학습지후기
- coroutine
- 코틀린
- 일본어문법
- androidstudio
- rxjava
- github
- 진짜학습지
- PR
- KotlinInAction
- 일본어기초
- 책리뷰
- ai
- 학습지
- Kotlin
- 진짜일본어
- Android
- posting
- GIT
- webflux
- suspend
- 인공지능
- 책추천
Archives
코딩하는 개굴이
[HackerRank] Compare Triplets (Kotlin) 본문
반응형
Compare Triplets : https://www.hackerrank.com/challenges/compare-the-triplets/problem
Compare the Triplets | HackerRank
Compare the elements in two triplets.
www.hackerrank.com
간단한 문제이다.

fun compareTriplets(a: Array<Int>, b: Array<Int>): Array<Int> {
// Write your code here
var aScore = 0
var bScore = 0
for(i in a.indices) {
if(a[i] < b[i]) bScore++
else if(a[i] > b[i]) aScore++
}
val arr = Array(2) { 0 }
arr[0] = aScore
arr[1] = bScore
return arr
}
fun main(args: Array<String>) {
val a = readLine()!!.trimEnd().split(" ").map{ it.toInt() }.toTypedArray()
val b = readLine()!!.trimEnd().split(" ").map{ it.toInt() }.toTypedArray()
val result = compareTriplets(a, b)
println(result.joinToString(" "))
}
반응형
'알고리즘 > HackerRank' 카테고리의 다른 글
[HackerRank] Extra Long Factorials (Kotlin) (0) | 2022.07.30 |
---|---|
[HackerRank] Super Reduced String (Kotlin) (0) | 2022.07.09 |
Comments