#include <iostream>
#include <string>
#include <stack>
using namespace std; bool isValid(string s) {
stack<char> a;
int len=s.size();
if(len==) return ;
if(len==) return ;
for(int i=;i<len;i++)
{
switch (s[i])
{
case ')':
{
if((a.size()!=)&&a.top()=='(') a.pop();
else return false;
break;
}
case '}':
{
if((a.size()!=)&&a.top()=='{') a.pop();
else return false;
break;
}
case ']':
{
if((a.size()!=)&&a.top()=='[') a.pop();
else return false;
break;
}
default:a.push(s[i]);
break;
}
}
cout<<a.size()<<endl;
if(a.size()==) return true;
else return false;
} int main() {
string s="){";
std::cout << isValid(s) << std::endl;
return ;
}

#leetcode刷题之路20-有效的括号的更多相关文章

  1. #leetcode刷题之路32-最长有效括号

    给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1:输入: "(()"输出: 2解释: 最长有效括号子串为 "()"示 ...

  2. python -- leetcode 刷题之路

    第一题 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], tar ...

  3. 使用Java+Kotlin双语言的LeetCode刷题之路(三)

    BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...

  4. #leetcode刷题之路13-罗马数字转整数

    罗马数字包含以下七种字符: I, V, X, L,C,D 和 M.字符 数值I 1V 5X 10L 50C 100D 500M 1000例如, 罗马数字 2 写做 II ,即为两个并列的 1.12 写 ...

  5. 使用Java+Kotlin双语言的LeetCode刷题之路(二)

    BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...

  6. 使用Java+Kotlin双语言的LeetCode刷题之路(一)

    LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 1 两数之和 给定一个整数数 ...

  7. #leetcode刷题之路40-组合总和 II

    给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合.candidates 中的每个数字在每个组合中只能使用一次.说 ...

  8. #leetcode刷题之路16-最接近的三数之和

    给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这三个数的和.假定每组输入只存在唯一答案. 例如,给定数 ...

  9. #leetcode刷题之路6- Z 字形变换

    将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列.比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下:L     C     I ...

随机推荐

  1. Cocos2d-js 开发记录:自定义按钮

    游戏开发总是有些特殊,一般的预制的UI无法满足要求.其实对于不复杂的功能,与其看文档还不如自己写一个.比如游戏中一个虚拟键盘,其中的按键在按下时会增长,变为原来的两倍高度,在原来高度上方显示按键的字如 ...

  2. ssh命令使用

    ssh是什么 ssh是一种通信协议,用于与另一台计算机通信,有多个实现版本,openssh属于开源实现 usage: ssh [-B bind_interface] [-b bind_address] ...

  3. oracle学习篇八:约束

    ----约束------- --1.主键约束--唯一标识,不能为空,通常用于ID--1>创建主键create table person(id varchar2(20) primary key,n ...

  4. Eclipse equinox implementation of OSGi

    Bundle package org.osgi.framework; public interface Bundle extends Comparable<Bundle> { int UN ...

  5. .NET开源工作流RoadFlow-表单设计-隐藏域

    隐藏域即<input type="hidden" value=""/>标签:

  6. 01_Quartz基础结构

    [各种任务调度的使用场景] 论坛每天凌晨统计论坛用户的积分排名. 论坛每半个小时生成精华文章. 每隔30分钟对锁定过期的用户解锁. 每月1号统计上个月各部门的业务数据. [Quartz 简介] Qua ...

  7. Android使用Fragment来实现TabHost的功能

    http://www.cnblogs.com/tiantianbyconan/p/3360938.html 好了,到此为止,我们已经用Fragment实现了类似TabHost的功能了,下面来看下各个F ...

  8. SharePoint2010 HTTP Error 503. The service is unavailable 解决方法

    1.更改系统管理员用户密码前提 因为更改系管理员用户密码会影响到 "SharePoint2010"正常运行,所在尽量不要更改系统管理员用户的密码, 必须更改密码的话,需要注意以两点 ...

  9. java实现多文件上传01

    1.html代码 <html> <head> <link rel="stylesheet" type="text/css" hre ...

  10. 【Leetcode】【Easy】Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...