728x90
코드 처리하기
class Solution {
fun solution(code: String): String {
var answer: String = ""
var mode = true // mode == 0
for (i in 0 until code.length){
if (mode){
if (code[i] == '1') mode = !mode
else{
if (i % 2 == 0) answer += code[i]
}
}else{
if (code[i] == '1') mode = !mode
else{
if (i % 2 == 1) answer += code[i]
}
}
}
return if (answer != "") answer else "EMPTY"
}
}
등차수열의 특정한 항만 더하기
class Solution {
fun solution(a: Int, d: Int, included: BooleanArray): Int = (0 until included.size).sumOf { if (included[it]) a + d * it else 0 }
}
주사위 게임 2
class Solution {
fun solution(a: Int, b: Int, c: Int): Int =
if (a == b && a == c){
(a + b + c) * (a * a + b * b + c * c) * (a * a * a + b * b * b + c * c * c)
}else if (a == b || b == c || a == c){
(a + b + c) * (a * a + b * b + c * c)
}else {
a + b + c
}
}
원소들의 곱과 합
class Solution {
fun solution(num_list: IntArray): Int {
var answer: Int = 1
var hap = num_list.sum()
for (i in num_list)
answer *= i
return if (answer > hap * hap) 0 else 1
}
}
이어 붙인 수
class Solution {
fun solution(num_list: IntArray): Int {
var odd : String = ""
var even : String = ""
num_list.forEach {
if (it % 2 == 0) even += it.toString()
else odd += it.toString()
}
return even.toInt() + odd.toInt()
}
}
728x90