We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9c12f7c commit 0e32552Copy full SHA for 0e32552
1 file changed
valid-parentheses/JustHm.swift
@@ -0,0 +1,24 @@
1
+// time: O(n) space: O(n)
2
+class Solution {
3
+ func isValid(_ s: String) -> Bool {
4
+ var answer = [Character]()
5
+ for char in s {
6
+ if let recent = answer.last {
7
+ if char == ")" && recent == "(" {
8
+ answer.removeLast()
9
+ continue
10
+ }
11
+ else if char == "]" && recent == "[" {
12
13
14
15
+ else if char == "}" && recent == "{" {
16
17
18
19
20
+ answer.append(char)
21
22
+ return answer.isEmpty
23
24
+}
0 commit comments