LeetCode: Valid Parentheses
来源:互联网 发布:windows net snmp 编辑:程序博客网 时间:2024/05/19 09:17
class Solution {
public:
bool isValid(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
stack<char> st;
for(int i=0;i<s.length();i++){
if(s[i]=='(')
st.push(s[i]);
else if(s[i]==')'){
if(st.empty()||st.top()!='(')
return false;
st.pop();
}
else if(s[i]=='{')
st.push(s[i]);
else if(s[i]=='}'){
if(st.empty()||st.top()!='{')
return false;
st.pop();
}
else if(s[i]=='[')
st.push(s[i]);
else if(s[i]==']'){
if(st.empty()||st.top()!='[')
return false;
st.pop();
}
else
return false;
}
return st.empty();
}
};
public:
bool isValid(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
stack<char> st;
for(int i=0;i<s.length();i++){
if(s[i]=='(')
st.push(s[i]);
else if(s[i]==')'){
if(st.empty()||st.top()!='(')
return false;
st.pop();
}
else if(s[i]=='{')
st.push(s[i]);
else if(s[i]=='}'){
if(st.empty()||st.top()!='{')
return false;
st.pop();
}
else if(s[i]=='[')
st.push(s[i]);
else if(s[i]==']'){
if(st.empty()||st.top()!='[')
return false;
st.pop();
}
else
return false;
}
return st.empty();
}
};
- LeetCode: Valid Parentheses
- LeetCode: Longest Valid Parentheses
- LeetCode: Valid Parentheses
- LeetCode Longest Valid Parentheses
- [Leetcode] Valid Parentheses
- LeetCode: Longest Valid Parentheses
- [Leetcode] Longest Valid Parentheses
- LeetCode : Valid Parentheses
- [leetcode]longest Valid Parentheses(!!)
- Leetcode: Valid Parentheses
- leetcode 52: valid parentheses
- [Leetcode] Longest Valid Parentheses
- leetcode Longest Valid Parentheses
- 【leetcode】Valid Parentheses
- 【leetcode】Longest Valid Parentheses
- [LeetCode]Longest Valid Parentheses
- [LeetCode]Valid Parentheses
- LeetCode-Valid Parentheses
- CPU : 什么是前端总线
- IplImage, CvMat, Mat 的关系和相互转换
- linux中文件描述符fd和文件指针flip的理解
- 『C/C++』ANSI C、C99、C11
- Global Hotkeys in WPF
- LeetCode: Valid Parentheses
- 任意进制(2-36内)与十进制间的转换
- Oracle小知识- Oracle KILLED会话的释放
- uva 10061 How many zero's and how many digits ?
- Android ADB server didn't ACK 解决方法(一张图让你解决问题)
- P2251-03量产失败修复成功DT111
- Linux下python升级至2.7步骤
- 网络子系统17_邻居子系统代理功能
- 抽象工厂模式(Abstract Factory)