Skip to content

Commit 85295ba

Browse files
committed
solve problem
1 parent 1176146 commit 85295ba

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

valid-parentheses/delight010.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
func isValid(_ s: String) -> Bool {
3+
let dictionary: [Character: Character] = [")":"(", "]":"[", "}":"{"]
4+
var stack: [Character] = []
5+
for char in s {
6+
if let closeBucket = dictionary[char] {
7+
if stack.isEmpty == false, stack.removeLast() == closeBucket {
8+
continue
9+
} else {
10+
return false
11+
}
12+
}
13+
stack.append(char)
14+
}
15+
16+
return stack.isEmpty
17+
}
18+
}
19+

0 commit comments

Comments
 (0)