当前位置:网站首页>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
边栏推荐
- Kotlin Compose 自定义 CompositionLocalProvider CompositionLocal
- [BJDCTF2020]The mystery of ip
- 020 C语言基础:C语言强制类型转换与错误处理
- Cultural tourism night tour | stimulate tourists' enthusiasm with immersive visual experience
- [station B up dr_can learning notes] Kalman filter 1
- Microservice system design -- Distributed timing service design
- Advanced Mathematics (Seventh Edition) Tongji University exercises 1-10 personal solutions
- Why does C throw exceptions when accessing null fields?
- LDR6028 手机设备一边充电一边OTG传输数据方案
- WPF open source control library extended WPF toolkit Introduction (Classic)
猜你喜欢

Ledrui ldr6035 usb-c interface device supports rechargeable OTG data transmission scheme.

Building lightweight target detection based on mobilenet-yolov4

Microservice system design -- distributed cache service design

低代码开发平台NocoBase的安装
![[station B up dr_can learning notes] Kalman filter 3](/img/40/d3ec97be2f29b76a6c049c26ff4998.gif)
[station B up dr_can learning notes] Kalman filter 3

Ldr6028 OTG data transmission scheme for mobile devices while charging

日志收集系統

nignx配置单ip限流

【B站UP DR_CAN学习笔记】Kalman滤波3

面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?
随机推荐
【Unity】UI交互组件之按钮Button&可选基类总结
014 C language foundation: C string
[array]bm94 rainwater connection problem - difficult
低代码开发平台NocoBase的安装
PostgreSQL基础命令教程:创建新用户admin来访问PostgreSQL
MySQL development environment
DAST black box vulnerability scanner part 6: operation (final)
跟着BUU学习Crypto(周更)
Fplan powerplan instance
021 basics of C language: recursion, variable parameters
Microservice system design -- service registration, discovery and configuration design
微服务系统设计——服务熔断和降级设计
Cultural tourism light show breaks the time and space constraints and shows the charm of night tour in the scenic spot
微服务系统设计——分布式事务服务设计
ERP demand and sales management Kingdee
A^2=E | 方程的解 | 这个方程究竟能告诉我们什么
010 C language foundation: C function
Nignx configuring single IP current limiting
1.5 use of CONDA
MySql的开发环境