你将得到一个由小写字母 a-z ,左括号 '(' 和右括号 ')' 构成的字符串 s。
你的任务是删除尽可能少的括号,使得 s 里面的括号匹配。
你需要返回删除括号后的字符串。
由于答案可能会有很多,所以你只需要返回任意一个正确答案。
例如:"()", "(())", "()()", "(())()" 是括号匹配的字符串, 而 ")(", "(()", "()()(", "()())" 则是括号不匹配的字符串。
没有括号的字符串(如:abcd)或空串 "" 也算一个括号匹配的字符串。
0≤0 leq0≤ s 的长度 ≤105leq 10^5≤105
你只能对原串进行括号删除的操作,其他操作将不被允许。
样例
样例1:
输入:
s = "a(b(c(de)fgh)"
输出:
"a(b(cde)fgh)"
解释:
正确答案有三个:"ab(c(de)fgh)","a(bc(de)fgh)","a(b(cde)fgh)"。
你只需要返回任何一个。
样例2:
输入:
s = "((("
输出:
""
解释:
空串也属于括号匹配的字符串。
#includeusing namespace std; string removeParentheses(string &s) { string num=""; int x=s.size(); int i,a=0; vector sum(x,0); for(i=0; i =0;i--) { if(sum[i]==2 && a>0) { a--; sum[i]=1; } } for(i=0;i > s; string str1=removeParentheses(s); cout << str1; return 0; }



