Skip to content

Instantly share code, notes, and snippets.

@teacons
Created November 27, 2021 16:02
Show Gist options
  • Save teacons/57d43ad96212db786b644c483c17aa38 to your computer and use it in GitHub Desktop.
Save teacons/57d43ad96212db786b644c483c17aa38 to your computer and use it in GitHub Desktop.
package ru.fbear.strings
class Brackets {
fun valid(bracketsString: String): Boolean {
var left = 0
var right = 0
for (sym in bracketsString) {
when (sym) {
'(' -> left++
')' -> right++
}
if (right > left) return false
}
return left == right
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment