当前位置:网站首页>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;
}边栏推荐
- How about opening an account for Haitong Securities? Is it safe
- [acwing] weekly competition
- El select drop-down box multi selection remote search anti display
- Programming in the novel [serial 17] the moon bends in the yuan universe
- D1-h development board - Introduction to Nezha development
- [C language] address book (static version)
- 除了钱,创业者还需要什么?专访明月湖创赛创投机构
- 接口测试
- Relevant interfaces of [asp.net core] option mode
- YOLO7 口罩识别实战
猜你喜欢

D1-H 开发板——哪吒 开发入门

达梦数据库tools包中的工具(操作达梦数据库)

Array - 59. Spiral matrix II

Programmation JDBC pour MySQL
关于电脑端同步到手机端数据

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

Storage structure and management disk. It's a bit like installing Win98. You need to partition and format the hard disk first

LeetCode高频题62. 不同路径:机器人从左上角到右下角的路径有多少条?纯概率排列组合问题,而不是动态规划题

Matlab wavelet toolbox import signal error (doesn't contain one dimensional single)

Can Verilog of synthetizable be integrated
随机推荐
I, AI doctoral student, online crowdfunding research topic
[Matplotlib drawing]
Leetcode high frequency question 62. different paths: how many paths does the robot have from the upper left corner to the lower right corner? Pure probability permutation and combination problem, not
"Morning reading" if you were in my position, what would you do? How do we do it,
Introduction to I2C Principle & Application of esp32
Mqtt connection, subscription and publishing can be realized without mqtt C library
What are the product life cycle, common project functions, and information flow
Memory search - DP
Inspiration from Buffett's shareholders' meeting 2021-05-06
DeFi項目的盈利邏輯 2021-04-26
Investment suggestions for overseas senior players (2) 2021-05-03
What if the content of software testing is too simple?
How can I open an account to buy financial products with a 6% income?
ospf终极实验——学会ospf世纪模板例题
[jailhouse article] a novel software architecture for mixed criticality systems (2020)
Investment suggestions for overseas senior players (3) 2021-05-04
海外资深玩家的投资建议(3) 2021-05-04
The font of Siyuan notes is thinner and lighter than that in other editors (atom, VSC, sublime)
Introduction and project development of MVVM and mvvmlight (I)
MVVM和MVVMLight简介及项目开发(一)