LeetCode
来源:互联网 发布:为什么监控无网络视频 编辑:程序博客网 时间:2024/04/29 09:33
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.
class Solution {public: bool isValid(string s) { stack<char> ans; if (s == "" || s.length() % 2) return false; for (int i = 0; i < s.length(); ++i) { switch (s[i]) { case '(': case '{': case '[': ans.push(s[i]); break; case ')': if (ans.empty()) return false; if (ans.top() == '(') ans.pop(); else ans.push(s[i]); break; case '}': if (ans.empty()) return false; if (ans.top() == '{') ans.pop(); else ans.push(s[i]); break; case ']': if (ans.empty()) return false; if (ans.top() == '[') ans.pop(); else ans.push(s[i]); break; } } if (ans.empty()) return true; return false; }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- java算法学习笔记--排序算法篇(上)
- JVM层对jar包字节码加密
- ioctl()函数详解
- Java8系列--Java Stream入门篇(流的操作)
- 用链表实现二叉树的实现(递归)
- LeetCode
- Centos7系统下安装opencv2.4.9+ffmpeg读取视频文件
- jsDOM增删改查操作
- 刚哥遇到了感情问题(二)
- OSD原理介绍
- day_17_可重入函数、线程同步
- 脚本文件
- Docker容器化快速构建多集群以太坊网络并部署智能合约
- 大二,唤醒 大三,coming