Solved
Valid parentheses: counting brackets passes the examples, fails hidden tests
Asked by Fatima Zahra Benali · 461 views · 2 replies
Fatima Zahra Benali4 messages
My idea was that every opening bracket needs a matching closing one, so I count them:
def is_valid(s):
return (s.count("(") == s.count(")")
and s.count("[") == s.count("]")
and s.count("{") == s.count("}"))
All the examples pass, but the hidden tests fail. What am I not seeing?