fork download
  1. def solution(*args):
  2. counts = 0
  3. for s in args:
  4. for c in s:
  5. if c == "(":
  6. counts += 1
  7. elif counts and c == ")":
  8. counts -= 1
  9. else:
  10. return False
  11. return False if counts else True
  12.  
  13. print(solution("()", "()"))
  14. print(solution("(())", "()"))
  15. print(solution(")(", ")("))
  16. print(solution("(()", "("))
Success #stdin #stdout 0.04s 9712KB
stdin
Standard input is empty
stdout
True
True
False
False