class Solution {
public:
string removeOuterParentheses(string S) {
stack<char> sta;
string res;
for(auto c : S)
{
if(c==')') sta.pop();
if(!sta.empty()) res.push_back(c);
if(c=='(') sta.push(c);
}
return res;
}
};
力扣 1021 刪除最外層括號*********
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
【棧】B020_LC_最大寬度坡(排序 / 單調棧)
ByteSinging
2020-07-08 05:01:10
leetcode **32. 最長有效括號
Sophia_fez
2020-07-06 05:19:10
leetcode 劍指 Offer 09. 用兩個棧實現隊列
Sophia_fez
2020-07-06 05:19:10
【棧】B019_LC_鏈表中的下一個最近的更大節點(暴力 / 單調棧)
ByteSinging
2020-07-04 16:33:36
【棧】C020_LC_刪除最外層的括號(記錄左右括號數)
ByteSinging
2020-07-04 16:33:36
【棧】B018_LC_不同字符的最小子序列(單調遞增棧 + 貪心)
ByteSinging
2020-07-01 15:52:49
leetcode 1475. 商品折扣後的最終價格(單調棧)
Sophia_fez
2020-06-28 06:44:17
leetcode150_逆波蘭表達式求值_棧
北大人工智能yjt
2020-06-27 08:45:12
【棧】B015_LC_刪除字符串中的所有相鄰重複項 II(暴力刪除 / 棧 + 對每種字符計數)
ByteSinging
2020-06-24 03:18:09
【棧】B016_LC_反轉每對括號間的子串(棧記錄左括號 + 局部翻轉)
ByteSinging
2020-06-24 03:18:09
leetcode **84. 柱狀圖中最大的矩形(單調棧題目表)
Sophia_fez
2020-06-19 20:28:39
leetcode *739. 每日溫度(單調棧)
Sophia_fez
2020-06-13 03:59:14
【棧】B013_LC_移除無效的括號(棧 + 標記)
zerostart0
2020-06-13 03:11:26
【LeetCode】單調棧相關練習總結
斗士(Carroll)
2020-06-08 21:23:30