Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- func maxDepth(_ s: String) -> Int {
- var count = 0
- var max = 0
- var b = ""
- for char in s {
- if char == "(" {
- b.append(char)
- count += 1
- } else if char == ")" {
- if max < count {
- max = count
- }
- if b.last == "(" {
- b.removeLast()
- }
- count -= 1
- }
- }
- if b.isEmpty {
- return max
- }
- return 0
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement