LeetCode 20. 有效的括號
class Solution {
public:
//判斷左右括號是否配對
bool match(char a, char b) {
if (a == '(' && b == ')' ||
a == '[' && b == ']' ||
a == '{' && b == '}')
return true;
return false;
}
inline bool isLeft(char c) {
if (c == '(' || c == '[' || c == '{') return true;
return false;
}
bool isValid(string s) {
stack<char> chs;
for (int i = 0; i < s.length(); i++) {
if (isLeft(s[i])) {
chs.push(s[i]);
}
else {
if (!chs.empty()) {
char tmp = chs.top();
if (!match(tmp, s[i]))
return false;
chs.pop();
}
else
return false;
}
}
if (!chs.empty()) return false;
return true;
}
};
相關文章
- Leetcode——20. 有效的括號LeetCode
- 【LeetCode】 20.有效的括號LeetCode
- [leetcode]有效的括號LeetCode
- Leetcode20. 有效的括號LeetCode
- 【LeetCode-棧】有效的括號LeetCode
- LeetCode有效的括號(Python)LeetCodePython
- LeetCode-20. 有效的括號(棧模擬)LeetCode
- Leetcode 20 有效的括號valid-parentheses(棧)LeetCode
- 最長有效括號
- [LeetCode] Longest Valid Parentheses 最長有效括號LeetCode
- 每日一題: 有效括號每日一題
- LeetCode 之 JavaScript 解答第20題 —— 有效的括號(Valid Parentheses)LeetCodeJavaScript
- [Go 演算法]20:有效括號(棧)Go演算法
- 括號生成-LeetCode22LeetCode
- leetcode:遞迴:括號生成LeetCode遞迴
- [LeetCode] Generate Parentheses 生成括號LeetCode
- 【leetcode】32. Longest Valid Parentheses 最長的有效匹配括號子串長度LeetCode
- 演算法題:判斷括號字串是否有效演算法字串
- LeetCode 3: PairsOfParentheses (括號匹配問題)LeetCodeAI
- LeetCode-022-括號生成LeetCode
- [LeetCode] Valid Parentheses 驗證括號LeetCode
- LeetCode - 22. 括號的生成(遞迴)1LeetCode遞迴
- Python有效括號字串判斷和深度計算Python字串
- 讓我們一起啃演算法----有效的括號演算法
- c++物件建立帶括號與無括號的區別C++物件
- JavaScript中圓括號()和方括號[]的一個特殊用法JavaScript
- 【leetcode】22. Generate Parentheses 合法括號串的所有組合LeetCode
- Matlab中的括號()[]{}Matlab
- 括號畫家
- JSON 字串中的中括號和大括號區別詳解JSON字串
- JavaScript 函式呼叫時帶括號和不帶括號的區別JavaScript函式
- 【leetcode】leetcode22括號生成通過程式碼及題解LeetCode
- [PHP字串]②--花括號{}的作用PHP字串
- Shell 括號總結
- Swift之花括號Swift
- 正則中括號點符號符號
- 萬用字元 and [] 中括號的用法字元
- Unix各種括號的用法總結