Is there an efficient method to find out if a string input uses correctly?
So, "((()))()" is correct. "()()(" is incorrect. "hi())(" is incorrect.
I have tried this:
def valid_parentheses(string):
utilList = [] for i in string:
utilList.append(i)
open = utilList.count("(")
close = utilList.count(")")
if (open + close) % 2 == 0:
return True
else:
return False