From 043a6f974987bca40c5babf37646c4e0ac574908 Mon Sep 17 00:00:00 2001 From: Yi Gu Date: Wed, 21 Mar 2018 21:24:40 -0700 Subject: [PATCH] [Stack] Optimize solution to Valid Parentheses --- Stack/ValidParentheses.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Stack/ValidParentheses.swift b/Stack/ValidParentheses.swift index 7a42a7fd..302ee9f2 100644 --- a/Stack/ValidParentheses.swift +++ b/Stack/ValidParentheses.swift @@ -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 == ")" { @@ -26,6 +26,6 @@ class ValidParentheses { } } - return stack.count == 0 + return stack.isEmpty } } \ No newline at end of file