十 用栈解决LeetCode20题括号的匹配
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAiIAAACWCAYAAADjcONgAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACAkSURBVHhe7Z09qyzJecc31xfQB3CgQCiRA+PEYDnzSyQwJ7Rj41CB7heY1Gx0g4022mQWvL7gYINlI4sxWljE4mhAGLHCcEAggaRdQbueeuunqp6q7nk7Peec3w+evdPd1VVPPd23/v/pmTv73gQAAACwEe9997t/Nv3Xz/47bgIAAAA8Hd6I/PWP/h4zAgAAAE+ONyICZgQAAACemmxEBMwIAAAAPCWFEREwIwAAAPBUNEZEwIwAAADAU2AaEQEzAgAAALema0QEzAgAAADckqER+cMfv8WMAAAAwM0YGhHhN7/5LWbkjvnmT3+a/vDNt9Pv//jNzUL6l3EugTznIM/rxmvKE+AlsmhEhF//+v8wI3fIt25Rsxa8W8W5iyh52kGe142XnifAS2WVERF++cv/9WbE5nE67HbT4TFuRo77h+lhf4xbYx4Pu9VtL+M47R+W8optFqLtwq5DHzfO7uDOsvH182PZfd76HZwV50Ce/TgH8uzHOdxTnvJ3flf/ZX88TLvBOqFZu46aa7OM01lrWmSN3Lv/3obxPGSdjWMf96qd2l/j52bMOXJfdZN5pLW/E/p+kBpYbczo5OnnsPJ6FjVPnKp9JY0R+d3vfh9fhS+r1mHiEqv/8vgL626KvSvoiuvrCOK/ru25xAu8d3kNxxobBEHm15zvb4hT/nKqcYybaakW7QL3+fT+v/50ev+zer8Vru3uk+nL9HrleefQ9jMY77MPp598/FW738cd5VnEV9NHu59OP/7g87h9R3n+4pPpJ91c7q+eX378b9OPXRsfd1xPn1/++5Pi0jxtkRLxW78uhjWuMTMaS7jcOnTIb3zK/dKTX8/rY0Zcsn7LGClvbQz0/oAyHF4UZT2X7bRf6ujW573KeWE9D33eS90kl4GorzGmJ5mjmOcJF6+9J5c1c0RhRMSEfOc7350++Y9P/faP/uYfpn//5D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QvAMDL5GIjMouRLKQiggsRxXLWESdCRrtGlzrtejE8f1E8LAEq5zcS6MCZRqSYpyWCsV8RMJmkb1+3K0U5481FP6cs8GafQuw3R+or1EbXJBgB3bYKnZuMV+VanK+u1ykfx/g+6mt9d/eB6q+eAADAK+A6X1YFAAAAOAOMCAAAAGwGRgQAAAA2AyMCAAAAm4ERAQAAgM3AiAAAAMBmYEQAAABgI6bp/wGxcGoHzNUKRwAAAABJRU5ErkJggg==" alt="" />
package com.lt.datastructure.Array;
import java.util.Stack;
/**
* 括号的匹配
*
* 遍历字符串s,如果是左括号,入栈
* 如果当前字符是右括号,栈为空,则匹配失败
* 如果当前字符是右括号,栈不为空,将其与栈顶字符匹配,匹配不成功则返回false
* 遍历判断结束后,当且仅当栈为空,匹配成功
*/
public class Solution { public boolean isValid(String s) {
Stack<Character> stack = new Stack<>();
for(int i=0; i<s.length(); i++){
char c = s.charAt(i);
//case:左括号
if(c=='(' || c=='[' || c=='{'){
stack.push(c);
}
else{
//case:右括号
if(stack.isEmpty()) return false; char chartop = stack.pop();
if(c==')' && chartop !='(') return false;
if(c==']' && chartop !='[') return false;
if(c=='}'&& chartop!='{') return false;
}
}
return stack.isEmpty();
}
//测试用例
public static void main(String[] args) {
System.out.println(new Solution().isValid("(){}"));
}
}
十 用栈解决LeetCode20题括号的匹配的更多相关文章
- 用栈解决Largest Rectangle问题
一问题描述 Given n non-negative integers representing the histogram's bar height where the width of each ...
- 利用顺序栈解决括号匹配问题(c++)-- 数据结构
题目: 7-1 括号匹配 (30 分) 给定一串字符,不超过100个字符,可能包括括号.数字.字母.标点符号.空格,编程检查这一串字符中的( ) ,[ ],{ }是否匹配. 输入格式: 输入在一行 ...
- 《LeetBook》leetcode题解(20):Valid Parentheses[E]——栈解决括号匹配问题
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- 【js数据结构】栈解决括号不匹配问题
栈可以用来判断一个算术表达式中的括号是否匹配. 思路:读取算术表达式,遇到左括号'{'.'['.'('压入栈,栈的特点是后入先出,所以当遇到右括号'}'.']'.')'的时候,取出栈顶元素,是否满足读 ...
- 刁肥宅详解中缀表达式求值问题:C++实现顺序/链栈解决
1. 表达式的种类 如何将表达式翻译成能够正确求值的指令序列,是语言处理程序要解决的基本问题,作为栈的应用事例,下面介绍表达式的求值过程. 任何一个表达式都是由操作数(亦称运算对象).操作符(亦称运算 ...
- hdu 3666(差分约束,手动栈解决超时问题)
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- LeetCode 第20题--括号匹配
1. 题目 2.题目分析与思路 3.代码 1. 题目 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭 ...
- 【Java EE 学习 69 上】【struts2】【paramsPrepareParamsStack拦截器栈解决model对象和属性赋值冲突问题】
昨天有同学问我问题,他告诉我他的Action中的一个属性明明提供了get/set方法,但是在方法中却获取不到表单中传递过来的值.代码如下(简化后的代码) public class UserAction ...
- 一起talk C栗子吧(第二十回:C语言实例--括号匹配)
各位看官们,大家好.前几回中咱们说了堆栈的原理,而且举了实际的样例进行讲解,这一回咱们说的例 子是:括号匹配. 括号匹配使用了堆栈的原理,大家能够从样例看出来.所以我们把它们放在一起.闲话 休提.言归 ...
随机推荐
- Python日期
1. datatime from datetime import datetime, date now = datetime.now() print(now) # 2020-01-20 01:24:0 ...
- 二叉树性质 n0=n2+1
假设树的节点个数为n,那么n=n0+n1+n2,并且边的个数等于n-1,那么 n-1=n22+n1 则 n0+n1+n2-1=n22+n1,即n0=n2+1.
- 配置 DNS
配置 DNS 如何自定义配置容器的主机名和 DNS 呢?秘诀就是 Docker 利用虚拟文件来挂载容器的 3 个相关配置文件. 在容器中使用 mount 命令可以看到挂载信息: $ mount /de ...
- 02-12Android学习进度报告十二
今天学习了ListView的焦点问题,基本了解了ListView的使用内容. 首先可以为抢占了控件的组件设置:android:focusable="false" 只需为抢占了Lis ...
- 【SSM】日志框架 logback
logback.xml <?xml version="1.0" encoding="UTF-8" ?> <configuration scan ...
- spark-调节executor堆外内存
什么时候需要调节Executor的堆外内存大小? 当出现一下异常时: shuffle file cannot find,executor lost.task lost,out of memory 出现 ...
- python nohup linux 后台运行输出
遇到问题 nohup python flush.py & 这样运行,生成了nohup.out文件,但是内容始终是空的,试了半天也不行.浪费了不少时间.原因 python的输出又缓冲,导致out ...
- jupyter配置 nbextension
jupyter contrib nbextension install --user --skip-running-check No module named 'pysqlite2' 解决方法:打开此 ...
- Python回收机制
1.小整数对象池 整数在程序中的使用非常广泛,python 为了优化速度,使用了小整数对象池,避免整数频繁申请和销毁和内存空间. Python 对小整数的定义事[-5, 257]这些整数对象的hi提前 ...
- teraterm中log中加入时间戳
步骤: 1.Setup->Additional settings->log->Timestamp(Local Time) 2.记录log.File->log(Teraterm. ...