LeetCode:Valid Parentheses
2015-08-04 11:25
363 查看
Given a string containing just the characters
The brackets must close in the correct order,
'(',
')',
'{',
'}',
'['and
']', determine if the input string is valid.
The brackets must close in the correct order,
"()"and
"()[]{}"are all valid but
"(]"and
"([)]"are not.
class Solution { public: bool isValid(string s) { stack<char> cstack; string left="({["; string right=")}]"; for(auto c:s) { if(left.find(c)!=s.npos) cstack.push(c); else if(cstack.empty()||cstack.top()!=left[right.find(c)]) return false; else cstack.pop(); } return cstack.empty(); } };
相关文章推荐
- dedecms(<V5.7sp1) /install/index.php RFI
- Android使用信号量Semaphore进行多线程任务调度
- js的本地存储localstorge
- maven + gitlab工程发布操作
- My C++ Study Notes
- Spring MVC 静态资源处理
- 51nod 算法马拉松4 B递归(YY)
- iOS 常用到的打电话webview
- 运行spark示例Pi可能出现的问题及解决
- ios手柄研究
- Oracle中的视图理解
- hdu5301 填满房间最大的矩形的最小值
- poj3301
- the import javax.serlet cannot be solved.和Httpservlet cannot be resolved to a type
- sql中return和returns的区别
- npm 安装sockte.io 报错 shasum check failed for。。。。
- PowerDesigner 小技巧
- Python中通过函数对象创建全局变量
- uCOS-II移植到51单片机任务切换压栈和出栈的操作
- UI03_UIViewController