leetcode 20. 有效的括号


/*
* * @param {string} s * @return {boolean} */ var isValid = function(s) { let tmpStack = []; for(let i = 0; i < s.length; i++){ let el = s[i]; if(el=='(' || el=='{' || el =='['){ tmpStack.push(el); } else { if(el == ')' && tmpStack[tmpStack.length-1]=='('){ tmpStack.pop(); } else if (el == ']' && tmpStack[tmpStack.length-1] == '['){ tmpStack.pop(); } else if (el == '}' && tmpStack[tmpStack.length-1] == '{'){ tmpStack.pop(); } else { tmpStack.push(el); } } } if(tmpStack.length){ return false; } else { return true; } };

 

posted @ 2021-05-20 02:16  KYSpring  阅读(45)  评论(0编辑  收藏  举报