题目:给定一串只有“(”和“)”的字符串,要求只能删除配对的“()”,使得字符串无法再删除配对的括号
思路:双指针,左指针以左括号为结束条件,右指针以右括号为结束条件。
s = input()
ans = []
i, j = 0, len(s) - 1
while i < j:
while i < j and s[i] == ')':i += 1
while i < j and s[j] == '(':j -= 1
if i < j and s[i]=='(' and s[j]==')':
ans+=[i+1,j+1]
i += 1
j -= 1
if len(ans)==0:print(0)
else:
print(1)
ans.sort()
print(len(ans))
print(*ans)