当前位置:网站首页>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 implicitly passes the parameter compositionlocalprovider
- Fastdds server records - Translation-
- Argo Workflows —— Kubernetes的工作流引擎入门
- 008 C语言基础:C判断
- 012 C language foundation: C array
- Description of replacement with STM32 or gd32
- halcon常用仿射变换算子
- LDR6028 手机设备一边充电一边OTG传输数据方案
- Fplan powerplan instance
- Microservice system design -- distributed transaction service design
猜你喜欢

Argo workflows - getting started with kubernetes' workflow engine

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

ERP demand and sales management Kingdee

Fplan powerplan instance

如何让 EF Core 6 支持 DateOnly 类型

2022-06-26: what does the following golang code output? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { type

How to systematically learn LabVIEW?

渗透测试-目录遍历漏洞

MySql的开发环境

微服务系统设计——分布式缓存服务设计
随机推荐
014 C language foundation: C string
USB DRIVER
Static timing analysis OCV and time derive
DAST black box vulnerability scanner part 6: operation (final)
[station B up dr_can learning notes] Kalman filter 3
Facing the "industry, University and research" gap in AI talent training, how can shengteng AI enrich the black land of industrial talents?
真xx相来了?测试/开发程序员为什么不愿意加班,这是个疯狂的状态......
012 C language foundation: C array
018 basics of C language: C file reading and writing
微服务系统设计——分布式定时服务设计
Fplan power planning
021 C语言基础:递归,可变参数
WPF 开源控件库Extended WPF Toolkit介绍(经典)
高等数学(第七版)同济大学 习题1-10 个人解答
006 C language foundation: C storage class
Installing MySQL on Windows
Building lightweight target detection based on mobilenet-yolov4
微服务系统设计——服务链路跟踪设计
Games101 job 7 improvement - implementation process of micro surface material
IOS development: understanding of dynamic library shared cache (dyld)