我在做反括号
def reverse_parentheses(s):
"""
Reverse the strings contained in each pair of matching parentheses,
starting from the innermost pair. The results string should not contain
any parentheses.
>>> reverse_parentheses('a(bc)de')
'acbde'
>>> reverse_parentheses(
... 'The ((quick (brown) (fox) jumps over the lazy) dog)'
... )
'The god quick nworb xof jumps over the lazy'
"""
chars = list(s)
open_bracket_indexes = []
for i, c in enumerate(chars):
if c == '(':
open_bracket_indexes.append(i)
elif c == ')':
j = open_bracket_indexes.pop()
chars[j:i] = chars[i:j:-1]
if open_bracket_indexes:
raise ArgumentError('Unclosed parenthesis')
print(''.join(c for c in chars if c not in '()'))
s = input()
reverse_parentheses(s)
描述1要做什么
描述2做什么
结果,第10次测试总是失败
我用了很多算法,他们总是在10号失败. 同样的问题也发生在不久前: 堆栈溢出: the source code and a lot of others519/how-do-i-reverse-the-strings-contained-in-each-pair-of-matching-parentheses-sta">seems like the same thing, but nothing works at 10th个 LeetCode: the source code and a lot of others
使用的代码:
leetcode-recursion_based_and_stack_solution, (字面意思是其他leetcode解决方案与之前类似)
这个问题90%的原因是"糟糕"的测试,写得很差,只要这个"问题"存在,下面有链接和答案