Skip to content

Commit

Permalink
[Stack] Optimize solution to Valid Parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
soapyigu committed Mar 22, 2018
1 parent 48ee71f commit 043a6f9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Stack/ValidParentheses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

class ValidParentheses {
func isValid(s: String) -> Bool {
func isValid(_ s: String) -> Bool {
var stack = [Character]()

for char in s.characters {
for char in s {
if char == "(" || char == "[" || char == "{" {
stack.append(char)
} else if char == ")" {
Expand All @@ -26,6 +26,6 @@ class ValidParentheses {
}
}

return stack.count == 0
return stack.isEmpty
}
}

0 comments on commit 043a6f9

Please sign in to comment.