当前位置:网站首页>leetcode-20. Valid parentheses -js version
leetcode-20. Valid parentheses -js version
2022-06-27 04:29:00 【Qianfan at the front】
subject

Code
/** * Ideas : Use stack * practice : Traversal string * If it is an open parenthesis, it will be added to the stack ; * If it is a right parenthesis, it matches the nearest character in the stack to see if it is paired ; * If matching, the left parenthesis will be treated as a stack , Invalid mismatch proof string */
var isValid = function(s) {
let stack = [], length = s.length;
if (length % 2) return false
for (let item of s) {
if (item === '{' || item === '[' || item === '(') {
stack.push(item);
} else {
if (stack.length && stack.pop() === leftOf(item)) {
continue;
} else {
return false;
}
}
}
return !stack.length;
};
var leftOf = function(s) {
if (s === ')') return '(';
if (s === ']') return '[';
return '{';
}
Reference material
边栏推荐
- ERP需求和销售管理 金蝶
- DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
- Cultural tourism light show breaks the time and space constraints and shows the charm of night tour in the scenic spot
- 012 C language foundation: C array
- 017 basics of C language: bit field and typedef
- FastDDS的服务器记录-译-
- Kotlin compose compositionlocalof and staticcompositionlocalof
- 笔记本电脑没有WiFi选项 解决办法
- MySQL development environment
- Microservice system design -- unified authentication service design
猜你喜欢
![[数组]BM94 接雨水问题-较难](/img/2b/1934803060d65ea9139ec489a2c5f5.png)
[数组]BM94 接雨水问题-较难
![Golang Hello installation environment exception [resolved]](/img/30/bddba695e4c0059102e86de346b58d.png)
Golang Hello installation environment exception [resolved]

渗透测试-目录遍历漏洞

Log collection system

文旅灯光秀打破时空限制,展现景区夜游魅力

日志收集系統

Mobilenet series (4): mobilenetv3 network details

微服务系统设计——服务注册与发现和配置设计

Network structure and model principle of convolutional neural network (CNN)

面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?
随机推荐
iOS开发:对于动态库共享缓存(dyld)的了解
WPF open source control library extended WPF toolkit Introduction (Classic)
Further exploration of handler (Part 2) (the most complete analysis of the core principles of handler)
低代码开发平台NocoBase的安装
mysql数据库基础:DQL数据查询语言
Microservice system design -- distributed lock service design
Penetration test - directory traversal vulnerability
快速掌握 ASP.NET 身份认证框架 Identity - 通过邮件重置密码
高等数学(第七版)同济大学 习题1-10 个人解答
微服务系统设计——消息缓存服务设计
011 C语言基础:C作用域规则
如何系统学习LabVIEW?
MATLAB | 基于分块图布局的三纵坐标图绘制
Kotlin Compose 隐式传参 CompositionLocalProvider
Six possible challenges when practicing Devops
014 C language foundation: C string
Kotlin Compose compositionLocalOf 与 staticCompositionLocalOf
015 C语言基础:C结构体、共用体
USB DRIVER
百度飞桨“万有引力”2022首站落地苏州,全面启动中小企业赋能计划