4.1.1 Valid Parentheses
来源:互联网 发布:成都java培训班 编辑:程序博客网 时间:2024/05/18 00:15
原题链接:https://oj.leetcode.com/problems/valid-parentheses/
这题简单。一次过。
public class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<Character>(); char c; for(int i = 0; i < s.length(); i++){ c = s.charAt(i); if(c == '(' || c == '[' || c == '{'){ stack.push(c); } else if (c == ')' || c == ']' || c == '}'){ //dont forget this: there are more right parenthese if(stack.size() == 0) return false; char d = stack.peek(); if(c==')' && d!='(') return false; if(c==']' && d!='[') return false; if(c=='}' && d!='{') return false; else stack.pop(); } } //return true; return stack.size() == 0; }}
0 0
- 4.1.1 Valid Parentheses
- 4.1.1 Valid Parentheses
- 4.1.1—栈—Valid Parentheses
- 4.1.2 Longest Valid Parentheses
- 4.1.2 Longest 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
- 2010 Asia Fuzhou Regional Contest HDOJ 3694 Fermat Point in Quadrangle
- [学习笔记]C和C++中指针的基础知识点(一)
- ubuntu/linux mint 创建proc文件的三种方法(二)
- ubuntu/linux mint 创建proc文件的三种方法(三)
- ubuntu/linux mint 创建proc文件的三种方法(四)
- 4.1.1 Valid Parentheses
- Best Time to Buy and Sell Stock III
- hdu 3485——Count 101
- 华为招聘机试整理2:判断一个数组的元素是否是回文
- 华为招聘机试整理3:数组比较
- 华为招聘机试整理4:手机号码合法性判断
- 3个概念
- 【Android常用控件】EditText常用属性【二】:为文本输入框指定软键盘类型和软键盘回车键图标设置
- 黑客攻防入门秘籍 学习笔记(一)