[, {, (
는 push 한다.], }, )
는 pop 명령어라고 보면 된다.체크해야 되는것
fun isComplete(sb: StringBuilder) : Boolean{
val buckets = mapOf(']' to '[', '}' to '{', ')' to '(')
val first = sb.first()
if(buckets.keys.contains(first)) return false
val stack: Stack<Char> = Stack()
sb.forEach {
when(it) {
'[', '{', '(' -> stack.push(it)
']', '}', ')' -> {
if(stack.isEmpty()) return@forEach
val closed = stack.pop()
if(closed != buckets[it]) return false
}
}
}
return stack.isEmpty()
}