Given a string containing just the characters '('')''{''}''[' and ']', determine if the input string is valid.

The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.

Subscribe to see which companies asked this question

class Solution {
public:
bool isValid(string s) {
stack<char> store;
for (auto c : s) {
if (c == '(' || c == '{' || c == '[')
store.push(c);
else {
if (store.empty()) return false;
if (c == ')' && store.top() == '('){
store.pop();
}
else if (c == '}' && store.top() == '{'){
store.pop();
}
else if (c == ']' && store.top() == '['){
store.pop();
}
else
return false;
}
}
return store.empty();
}
};

最新文章

  1. Java的概述以及语法
  2. BZOJ 1014 【JSOI2008】 火星人prefix
  3. 《高级Web应用程序设计》课程学习资料
  4. javascript 的字符串原生方法
  5. asp.net 中json字符串转换
  6. (转)在javascript中关于submit和button提交表单区别
  7. OpenSUSE 13.2安装Texlive2014+Texmaker+Lyx
  8. C# 通过url地址获取页面内容
  9. 后端api规范说明文档
  10. Shell 自动化部署免密登录
  11. Essential Phone刷机教程
  12. Dan版本的nnet2
  13. 用Docker启动php-5.6 fpm服务配合宿主机nginx运行php测试环境
  14. Celery 在Windows下启动worker时出现错误:ValueError: not enough values to unpack (expected 3, got 0)
  15. Delphi控件备份工具
  16. (第七周)评论alpha发布
  17. [Selenium]刷新页面 Refresh page
  18. java变量的命名使用规则
  19. Javascript基本代码
  20. 伪差IO分标准

热门文章

  1. ANGULARJS 动态编译添加到dom中
  2. 所思所想 关于asp.net界面业务分离
  3. xampp搭建服务器环境、html5新的input类型
  4. bzoj 2242: [SDOI2011]计算器
  5. UI UIView
  6. C++-模板的声明和实现为何要放在头文件中
  7. [转]ps/2键盘线序识别方法
  8. VMware-workstation-full-10.0.1-1379776 CN
  9. Windows 技术预览版 - 传言中的Win 10
  10. 将Ajax 中数组转换成字符串 封装成类