Valid Parentheses
来源:互联网 发布:手机qq透明主题软件 编辑:程序博客网 时间:2024/06/05 13:22
class Solution {public: bool isValid(string s) { if(s.empty()||s.size()==1) return false; stack<char> stackdata; int i=0; const int n=s.size(); while(i<n) { while(s[i]=='(' || s[i]=='{' || s[i]=='[' && i<n) { stackdata.push(s[i]); ++i; } while(s[i]==')' || s[i]=='}' || s[i]==']' && i<n) { if(!stackdata.empty()) { char temp=stackdata.top(); stackdata.pop(); if(temp=='('&& s[i]!=')' || temp=='['&& s[i]!=']'|| temp=='{'&& s[i]!='}') return false; if(temp=='('&& s[i]==')' || temp=='['&& s[i]==']'|| temp=='{'&& s[i]=='}') ++i; } else return false; } } if(!stackdata.empty()) return false; else return true; }};
0 0
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- bootloader核心初始化
- Java--OOP细节(一)
- Win8 运行命令大全
- [设计模式] 单体模式及实现
- 黑马程序员——学习日记之--常见的其他对象
- Valid Parentheses
- Linux系统中普通文件和目录文件的区别
- javascript(四)window对象
- woocomerce商品属性用颜色或者属性代替方案
- linux如何查看端口相关信息
- xml应用以及从数据库读出数据形成XML,XML的查询,xpath
- memcache带图形界面监控工具memcachephp--监控memcache的性能
- Common Subsequence(HDU-1159)
- VIJOS P1493 传纸条