LeetCode20题不多说上代码

public boolean isValid(String s){
Stack<Character> stack = new Stack<Character>();
for (int i=0;i<s.length();i++){
char c = s.charAt(i);
if (c=='('||c=='['||c=='{')
stack.push(c);
else{
//栈没字符匹配失败
if (stack.isEmpty())
return false;
char topChar = stack.pop();
if (c==')'&&topChar!='(')
return false;
if (c==']'&&topChar!='[')
return false;
if (c=='}'&&topChar!='{')
return false; }}
return stack.isEmpty();
}

LeetCode第20题的更多相关文章

  1. leetcode第20题--Valid Parentheses

    Problem: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if ...

  2. LeetCode 第20题--括号匹配

    1. 题目 2.题目分析与思路 3.代码 1. 题目 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭 ...

  3. LeetCode第[20]题(Java):Valid Parentheses

    题目:有效的括号序列 难度:Easy 题目内容: Given a string containing just the characters '(', ')', '{', '}', '[' and ' ...

  4. LeetCode第20题:有效的括号

    问题描述: 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空 ...

  5. 【LeetCode算法-20】Valid Parentheses

    LeetCode第20题 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determin ...

  6. 【JavaScript】【dp】Leetcode每日一题-解码方法

    [JavaScript]Leetcode每日一题-解码方法 [题目描述] 一条包含字母 A-Z 的消息通过以下映射进行了 编码 : 'A' -> 1 'B' -> 2 ... 'Z' -& ...

  7. 【python】Leetcode每日一题-二叉搜索迭代器

    [python]Leetcode每日一题-二叉搜索迭代器 [题目描述] 实现一个二叉搜索树迭代器类BSTIterator ,表示一个按中序遍历二叉搜索树(BST)的迭代器: BSTIterator(T ...

  8. 【python】Leetcode每日一题-螺旋矩阵2

    [python]Leetcode每日一题-螺旋矩阵2 [题目描述] 给你一个正整数 n ,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix . ...

  9. leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

随机推荐

  1. ssm学习的第一个demo---crm(2)

    第四步:                  别名不区分大小写:入参为基本类型,#{可以随便写} 把静态资源(jsp.css.js.fonts)导入到项目中 第五步: 创建Contrller类(和普通j ...

  2. 安装 docker管理 工具 页面 portainer

    sudo docker run -d -p 7998:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data ...

  3. poi excel文件名或者内容中文乱码

    1.文件名乱码处理 // excel文件名 String fileName="我报表"; final SimpleDateFormat formatter = new Simple ...

  4. Mysql 储存引擎

    查看当前版本支持哪些储存引擎 mysql> show engines; InnoDB 支持事务机制 : 保证操作安全性 行级锁定 : 开销大,加锁慢:会出现死锁:锁定粒度最小,发生锁冲突的概率最 ...

  5. offsetof使用小结

    先上例子 #include <stdio.h> #include <stdlib.h> /* offsetof example */ #include <stddef.h ...

  6. django 使用mysql 数据库

    在 django 创建项目中 默认使用的是  splite3 数据库,不是mysql 数据库,要使用mysql ,要做一些配置: 在 settings.py 中修改如下: DATABASES = { ...

  7. 【JEECG技术文档】online自定义模板的使用

    一. 业务背景 客户需要快速开发一个信息采集的功能模块,并使用已规划好的页面,实现个性化页面展示,使用标准左右布局的Table或DIV风格的页面表现力不强,不能满足客户的个性化页面需要 二. 需求 1 ...

  8. How to make MySQL handle UTF-8 properly

    To make this 'permanent', in my.cnf: [client] default-character-set=utf8 [mysqld] character-set-serv ...

  9. 爬虫--Scrapy-持久化存储操作

    总体概况 持久化存储操作: a. 磁盘文件 a) 基于终端指令 i. 保证parse方法返回一个可迭代类型的对象(存储解析到的页面内容) ii. 使用终端指令完成数据存储到制定磁盘文件中的操作 1. ...

  10. Spring Cloud限流详解

    转自:https://blog.csdn.net/tracy38/article/details/78685707 在高并发的应用中,限流往往是一个绕不开的话题.本文详细探讨在Spring Cloud ...