Created
November 27, 2021 16:02
-
-
Save teacons/57d43ad96212db786b644c483c17aa38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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