当前位置:网站首页>20. Valid Parentheses有效的括号
20. Valid Parentheses有效的括号
2022-07-23 18:23:00 【DXB2021】
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。
An input string is valid if:
有效字符串需满足:
Open brackets must be closed by the same type of brackets.
左括号必须用相同类型的右括号闭合。
Open brackets must be closed in the correct order.
左括号必须以正确的顺序闭合。
Example 1:
Input: s = "()"
Output: true
示例 1:
输入:s = "()"
输出:true
Example 2:
Input: s = "()[]{}"
Output: true
示例 2:
输入:s = "()[]{}"
输出:true
Example 3:
Input: s = "(]"
Output: false
示例 3:
输入:s = "(]"
输出:false
示例 4:
输入:s = "([)]"
输出:false
示例 5:
输入:s = "{[]}"
输出:true
Constraints:
1 <= s.length <= 104
s consists of parentheses only '()[]{}'.
提示:
1 <= s.length <= 104
s 仅由括号 '()[]{}' 组成
C语言:(失败)
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;
}边栏推荐
- Redux求和案例详解版教程
- Element positioning in selenium is correct, but the operation fails. Six solutions are all finalized
- C language leak detection and filling (1)
- idea 选中代码生成方法
- 行业分析| 物流对讲
- R language mapping: coordinate axis setting
- 【Unity项目实践】委托
- Robot decision-making system based on self-learning (daki technology, Zhao kaiyong)
- SecureCRT乱码问题解决方法[通俗易懂]
- R语言使用ggpubr包的ggarrange函数将多幅图像组合起来、使用ggexport函数将可视化图像保存为bmp格式(width参数指定宽度、height参数指定高度、res参数指定分辨率)
猜你喜欢

Why are there Chinese materials and web pages for foreign chips?

Analyse de l'industrie | interphone logistique
![[英雄星球七月集训LeetCode解题日报] 第23日 字典树](/img/e3/74cb4ce8aa08e0ea90e26bb2d197c3.png)
[英雄星球七月集训LeetCode解题日报] 第23日 字典树

PowerCLi 管理VMware vCenter 批量部署导出导入

时代潮头,华为将风帆对准数字金融的风与海

简历上写的电商,那请问Redis 如何实现库存扣减操作和防止被超卖?

为啥一问 JVM 就 懵B ?

ACM MM 2022 Oral | DIG: 自监督文字识别的新框架,刷新11个公开场景文字数据集的识别性能,平均提升5%...

Canvas draw text and clear draw

Robot decision-making system based on self-learning (daki technology, Zhao kaiyong)
随机推荐
Why are there Chinese materials and web pages for foreign chips?
ACM mm 2022 oral | dig: the new framework of self-monitoring character recognition refreshes the recognition performance of 11 public scene character data sets, with an average improvement of 5%
解密:智能化变电站中PTP时钟同步(北斗时钟服务器)
Huawei cloud stack [interview]
Usage of formatdatetime
PowerCLi 将虚拟机从Host01主机移动到Host02主机
Redis坏了怎么办?
R语言筛选dataframe指定的数据列、R语言排除(删除)dataframe中的指定数据列(变量)
Robot decision-making system based on self-learning (daki technology, Zhao kaiyong)
Powercli management VMware vCenter one click batch deployment OVF
(dry goods) introduce several common feature selection methods combined with scikit learn
Delete strategy of redis expired key [easy to understand]
3D point cloud course (VI) -- 3D target detection
.Net CLR R2R编译的原理简析
Understand chisel language. 21. Chisel sequential circuit (I) -- detailed explanation of chisel register
Basic process of process scheduling
Exch:POP3 和 IMAP4 操作指南
redis过期key的删除策略[通俗易懂]
【开发经验】开发项目踩坑集合【持续更新】
我在代码里面故意留个漏洞,违法吗?