/**
* @param {string} S
* @return {number}
*/
var minAddToMakeValid = function(S) {
let stack = [];
let len = S.length;
for(let i = 0; i < len; ++i) {
let popped = stack.pop();
if(!popped) {
stack.push(S[i]);
} else if(!popped || popped !== '(' || S[i] !== ')') {
stack.push(...[popped, S[i]])
}
}
return stack.length;
};
複製程式碼
Leetcode 921 Javascript
相關文章
- 921A鋼號 921A潛艇鋼
- Leetcode 513 javascriptLeetCodeJavaScript
- LeetCode 162 JavascriptLeetCodeJavaScript
- LeetCode #378 JavaScriptLeetCodeJavaScript
- LeetCode 747 JavaScriptLeetCodeJavaScript
- LeetCode 799 JavaScriptLeetCodeJavaScript
- Leetcode #463 JavascriptLeetCodeJavaScript
- Leetcode # 495 JavascriptLeetCodeJavaScript
- Leetcode 229 JavaScriptLeetCodeJavaScript
- Leetcode 611 javascript Valid Triangle NumberLeetCodeJavaScript
- 前端面試每日 3+1 —— 第921天前端面試
- LeetCode刷題(javascript,python3)LeetCodeJavaScriptPython
- Leetcode 685. Redundant Connection II JavascriptLeetCodeJavaScript
- LeetCode 70題 爬樓梯 -- JavaScriptLeetCodeJavaScript
- LeetCode 存在重複元素之JavaScriptLeetCodeJavaScript
- LeetCode7.整數反轉 JavaScriptLeetCodeJavaScript
- Leetcode 202 Happy Number Javascript 解決方案LeetCodeAPPJavaScript
- Leetcode之javascript解題(No33-34)LeetCodeJavaScript
- Leetcode javascript 3 longest-substring-without-repeating-charactersLeetCodeJavaScript
- 用 JavaScript 刷 LeetCode 的正確姿勢【進階】JavaScriptLeetCode
- LeetCode 之 JavaScript 解答第一題 —— 兩數之和(Two Sum)LeetCodeJavaScript
- LeetCode 之 JavaScript 解答第20題 —— 有效的括號(Valid Parentheses)LeetCodeJavaScript
- LeetCode 之 JavaScript 解答第169題 —— 求眾數 I(Majority Element)LeetCodeJavaScript
- 吉利汽車控股財報:2020年營收921億元 同比增長5%營收
- LeetCode演算法簡單題--JavaScript(每天一道題)LeetCode演算法JavaScript
- LeetCode 之 JavaScript 解答第69題 —— X 的平方根(Squrt(x))LeetCodeJavaScript
- JavaScript實現-LeetCode刷題-【對稱二叉樹】-第101題!!!JavaScriptLeetCode二叉樹
- 【Leetcode 346/700】79. 單詞搜尋 【中等】【回溯深度搜尋JavaScript版】LeetCodeJavaScript
- LeetCode 之 JavaScript 解答第150題 —— 逆波蘭表示式求值(Evaluate Reverse Polish Notation)LeetCodeJavaScript
- LeetCode 之 JavaScript 解答第141題 —— 環形連結串列 I(Linked List Cycle I)LeetCodeJavaScript
- LeetCode題解:264. 醜數 II,二叉堆,JavaScript,詳細註釋LeetCodeJavaScript
- LeetCode題解:127. 單詞接龍,雙向BFS,JavaScript,詳細註釋LeetCodeJavaScript
- 【LeetCode】如何學習LeetCode?LeetCode
- leetcodeLeetCode
- LeetCode 之 JavaScript 解答第23題 —— 合併K個有序連結串列(Merge K Sorted Lists)LeetCodeJavaScript
- LeetCode in actionLeetCode
- leetcode 238LeetCode
- LeetCode題解:641. 設計迴圈雙端佇列,使用佇列,JavaScript,詳細註釋LeetCode佇列JavaScript