Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-04-10 22:04:09
20. Valid Parentheses
给你一个s字串只包含三种刮号 (){}[],如果同种类的左刮号相邻右刮号表示他是一
个合法刮号,如果不同种类的左刮号配对右刮号表示不合法,返回字串s是否合法。
Example :
Input: s = "()"
Output: true
Input: s = "()[]{}"
Output: true
Example 3:
Input: s = "(]"
Output: false
思路:
1.刮号匹配可以用Stack处理,遇到左刮号就push,遇到右刮号就pop,如果
pop出来的刮号不匹配或是Stack为空就表示刮号非法。
Java Code:
作者: DDFox (冒险者兼清洁工)   2023-04-10 22:05:00
大师
作者: PyTorch (屁眼火炬)   2023-04-10 22:15:00
大师
作者: Che31128 (justjoke)   2023-04-10 22:17:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com