20. Valid Parentheses
来源:互联网 发布:什么软件看美剧最全 编辑:程序博客网 时间:2024/06/16 06:23
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.
bool isValid(string s) { if (s == "")return false; stack<char> res; unordered_map<char, char> mapsign = { { ')', '(' }, { '}', '{' }, { ']', '[' } }; for (int i = 0; i < s.size(); i++){ if (s[i] == '(' || s[i] == '{' || s[i] == '[')res.push(s[i]); else { if (!res.empty()){ if (mapsign[s[i]] == res.top())res.pop(); else return false; } else return false; } } if (!res.empty())return false; else return true;}
阅读全文
0 0
- LeetCode 20. Valid Parentheses
- [LeetCode] 20.Valid Parentheses
- LeetCode --- 20. Valid Parentheses
- LeetCode 20.Valid Parentheses
- [Leetcode] 20. Valid Parentheses
- 20.Valid Parentheses
- 20.Valid Parentheses
- 20. Valid Parentheses
- 【leetcode】20. Valid Parentheses
- [leetcode] 20.Valid Parentheses
- [leetcode] 20. Valid Parentheses
- 20. Valid Parentheses
- 20. Valid Parentheses
- 20. Valid Parentheses
- Leetcode 20. Valid Parentheses
- 20. Valid Parentheses LeetCode
- 20. Valid Parentheses
- 20. Valid Parentheses
- Ubuntu 网线直连树莓派
- c#快速入门2
- CSS 块级元素 行内元素
- 机器学习实战 决策树
- 二、策略模式——设计模式学习笔记
- 20. Valid Parentheses
- Python Challenge闯关游戏——持续更新
- Linux—基本命令
- RecyclerView回收机制分析--“取”
- shell脚本中的eval、‘‘和$()
- 描述符表(descriptor table) 学习总结
- 王一题一题一题题
- 数据库设计范式
- sprintf在51单片机中转换字符出错问题解决