当前位置:网站首页>20. Valid parentheses valid parentheses
20. Valid parentheses valid parentheses
2022-07-23 22:43:00 【DXB2021】
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
Given one only includes '(',')','{','}','[',']' String s , Determines whether the string is valid .
An input string is valid if:
Valid string needs to meet :
Open brackets must be closed by the same type of brackets.
Opening parentheses must be closed with closing parentheses of the same type .
Open brackets must be closed in the correct order.
The left parenthesis must be closed in the correct order .
Example 1:
Input: s = "()"
Output: true
Example 1:
Input :s = "()"
Output :true
Example 2:
Input: s = "()[]{}"
Output: true
Example 2:
Input :s = "()[]{}"
Output :true
Example 3:
Input: s = "(]"
Output: false
Example 3:
Input :s = "(]"
Output :false
Example 4:
Input :s = "([)]"
Output :false
Example 5:
Input :s = "{[]}"
Output :true
Constraints:
1 <= s.length <= 104
s consists of parentheses only '()[]{}'.
Tips :
1 <= s.length <= 104
s Brackets only '()[]{}' form
C Language :( Failure )
bool isValid(char * s){
int a=0;
for(int i=0;i<strlen(s);i++)
{
if(a[i]=='(')
a+=1;
else if(a[i]==')')
a-=1;
else if(a[i]=='{')
a+=2;
else if(a[i]=='}')
a-=2;
else if(a[i]=="[")
a+=3;
else if(a[i]=="]")
a-=3;
}
if(a==0)
return true;
else
return false;
}边栏推荐
- What are the product life cycle, common project functions, and information flow
- Data sorting and usage before torchvision.datasets.imagefolder
- Introduction to I2C Principle & Application of esp32
- 接口测试
- STM32+ESP8266+MQTT协议连接阿里云物联网平台
- Programmation JDBC pour MySQL
- 达梦数据库tools包中的工具(操作达梦数据库)
- Utilisation des fonctions fléchées es6
- 使用itextpdf提取PDF文件中的任意页码
- 小说里的编程 【连载之十八】元宇宙里月亮弯弯
猜你喜欢

D1-h development board - Introduction to Nezha development

作为开发,你不得不知道的三个性能测试工具|Jmeter、Apipost、JMH使用指南

还在为XShell破解烦恼,试试tabby

MySQL index transaction

openEuler 资源利用率提升之道 01:概论

I, AI doctoral student, online crowdfunding research topic

JDBC programming of MySQL

DeFi項目的盈利邏輯 2021-04-26

【golang学习笔记】包(package)的使用

ONEFLOW V0.8.0 officially released
随机推荐
年化收益率6%的理财产品
What are the product life cycle, common project functions, and information flow
小说里的编程 【连载之十七】元宇宙里月亮弯弯
ES6箭頭函數的使用
Is Ping An Securities' low commission account opening link safe? How to handle low commission
Multithreading problem: why should we not use multithreading to read and write the same socket connection?
【Unity3D日常BUG】Unity3D解决“找不到类型或命名空间名称“XXX”(您是否缺少using指令或程序集引用?)”等问题
fl studio 20.9更新中文版宿主DAW数字音频工作站
Can Verilog of synthetizable be integrated
Investment suggestions for overseas senior players (3) 2021-05-04
El select drop-down box multi selection remote search anti display
【AcWing】周赛
Video Number strengthens the fight against vulgar content: the content that violates public order and good customs must be eliminated
Sword finger offer II 115. reconstruction sequence
Neo4j application
Programming in the novel [serial 18] the moon bends in the yuan universe
视频号加强打击低俗内容:对违背公序良俗的内容必须赶尽杀绝
The font of Siyuan notes is thinner and lighter than that in other editors (atom, VSC, sublime)
【golang学习笔记】并发基础
[problem handling] merge made by the 'ort' strategy