Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
recursion for the win solution in Clear category for Remove Brackets by tthevis
def is_balanced(line: str) -> bool:
if line == '': return True
reduced_line = line.replace('[]','').replace('{}','').replace('()','')
if reduced_line == line: return False
return is_balanced(reduced_line)
def remove_brackets(line: str) -> str:
if is_balanced(line): return line
result = ''
for i in range(len(line)):
tmp_res = remove_brackets(line[:i] + line[i+1:])
if len(tmp_res) > len(result): result = tmp_res
return result
June 11, 2020
Comments: