**(leetcode_string) Valid Parentheses
来源:互联网 发布:python检测sql注入 编辑:程序博客网 时间:2024/06/08 18:45
Valid Parentheses
Total Accepted: 27208 Total Submissions: 97024My SubmissionsGiven 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.
Have you met this question in a real interview?
Yes
No
Discuss
利用stack~!
class Solution {public: bool isValid(string s) { stack<char> stk; int i; for(i=0;i<s.length();i++){ if(s[i]=='(' || s[i]=='[' || s[i]=='{') stk.push(s[i]); else{ if(!stk.empty()&&((stk.top()=='('&&s[i]==')') ||(stk.top()=='['&&s[i]==']')||(stk.top()=='{'&&s[i]=='}'))) stk.pop(); else return false; } } return stk.empty(); }};
0 0
- **(leetcode_string) Valid Parentheses
- *(leetcode_string) Valid Palindrome
- 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
- 大学学习
- Matlab clear, clc 和close函数
- java中setvisible放在最后
- DevExpress中TreeList的一个节点改变父节点也要改变的实例
- php 冒泡排序 快速排序
- **(leetcode_string) Valid Parentheses
- C#中的线程(一)入门
- 由8086看汇编语言之--MOV编
- C语言(四)
- 【汇编指令】数据处理指令之算术指令集
- 记录点滴之优化应用性能:Activity里面不要使用静态常量
- 批量删除
- iptables --- auto script
- camera录像过程一