Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- func isValid(_ s: String) -> Bool {
- if [")", "]", "}"].contains(s.first) { return false }
- if ["(", "[", "{"].contains(s.last) { return false }
- var str: String = ""
- for c in s {
- if str.last == "(" && c == ")" || str.last == "[" && c == "]" || str.last == "{" && c == "}" {
- str.removeLast()
- } else {
- str.append(c)
- }
- }
- return str.count == 0
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement