KotlinAlgorithm#3 (BOJ9012)

박채빈·2021년 10월 22일
0

KotlinAlgorithm

목록 보기
3/28
post-thumbnail

BOJ9012 괄호

링크

코드

import java.util.*

fun main() {
    val T = readLine()!!.toInt()

    repeat(T) {
        val input = readLine()!!
        val stack = Stack<Char>()

        try {
            input.forEach { if(it == '(') stack.push('(') else stack.pop() }
            println(if(stack.isEmpty()) "YES" else "NO")
        } catch (e: EmptyStackException) {
            println("NO")
        }
    }
}
profile
안드로이드 개발자

0개의 댓글