20. Valid Parentheses
来源:互联网 发布:用友软件凭证打印 编辑:程序博客网 时间:2024/06/06 00:11
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.
import java.util.Stack;public class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<Character>(); //使用foreach循环 for (char c : s.toCharArray()) { if (c == '(') stack.push(')'); else if (c == '{') stack.push('}'); else if (c == '[') stack.push(']'); else if (stack.isEmpty() || stack.pop() != c) return false; } return stack.isEmpty(); }}
阅读全文
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
- codeforces 822C
- 机器学习
- 文章标题
- SpringMVC 字节流实现播放多媒体
- 东软JavaWeb实训记-DAY5-MyBatis框架+jsp传值+登录过滤器
- 20. Valid Parentheses
- 锚点的作用及用法
- 用户
- HDU 4027 Can you answer these queries? (线段树 区间开方)
- 微修改前端框架,以满足项目需求
- 深度学习模型压缩方法综述(二)
- 《函数调用时参数、返回值所做的优化处理+编译器NRV优化》
- 【spark,rdd,2】RDD基本转换算子
- Android高级控件之AutoCompleteTextView,MultiAutopleteTextView,Spinner,ListView,ExpandableListView