Wildcard Brackets
mediumA templating engine emits strings containing (, ), and the wildcard *. Before rendering, each * must be rewritten as (, ), or the empty string.
Given such a string s, return True if some rewriting of the wildcards yields a balanced parenthesis string (every ( closed by a later ), every ) opened by an earlier (), else False. The empty string is balanced.
Example 1
in s = "(*)"
out True
Treat * as empty: "()" is balanced.
Example 2
in s = "(*))"
out True
Treat * as "(": "(())" is balanced.
Example 3
in s = ")("
out False
No wildcard can rescue a closer that comes first.
Constraints
- · 1 <= len(s) <= 10^4
- · s contains only '(', ')' and '*'
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.