当前位置:网站首页>leetcode:20. 有效的括号
leetcode:20. 有效的括号
2022-08-06 03:03:00 【心软且酷丶】
难度:简单
给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。
有效字符串需满足:
左括号必须用相同类型的右括号闭合。
左括号必须以正确的顺序闭合。示例 1:
输入:s = "()"
输出:true
示例 2:输入:s = "()[]{}"
输出:true
示例 3:输入:s = "(]"
输出:false
示例 4:输入:s = "([)]"
输出:false
示例 5:输入:s = "{[]}"
输出:true
提示:
1 <= s.length <= 104
s 仅由括号 '()[]{}' 组成题解
class Solution: def isValid(self, s: str) -> bool: stack = [] d = { ')':'(', '}':'{', ']':'[', } if len(s) % 2 == 1: return False for i in s: if i in d.values(): stack.append(i) elif i in d.keys(): if stack == [] or d[i] != stack.pop(): return False else: return False return not stack
边栏推荐
- Soul submitted a listing application to the Hong Kong Stock Exchange and continued to develop the social metaverse track
- 走!VR技术带你沉浸式看展
- KU115 PCIE bus data preprocessing board (multi-LVDS interface)
- pytest之assert断言的使用
- leetcode 17. Letter Combinations of Phone Numbers
- 入坑机器学习:二,监督学习
- C Student management system Delete the specified student node (general situation)
- LeetCode每日两题02:回文数 (均1200道)
- 相机标定 >> 坐标系转换@内参、外参
- 运维小白成长记——架构第10周
猜你喜欢
随机推荐
1321_一份BootLoader xmodem部分的协议分析
pcl point cloud networking vtk Delaunay point cloud networking
What skills should a test engineer have to get 30k?
测试工程师应该具备什么能力才能拿到30k?
odoo 15 会员模块的使用
LeetCode每日两题01:翻转单词前缀 (均1200道)
Wejo joins MONET alliance to further drive innovation in international mobility
软件工程-大学体育馆管理系统交互图
WPF 截图控件之移除控件(九)「仿微信」
nRF52833-QIAA-R nordic无线收发芯片
微信小程序 多选————四选二
KGAT recommendation system
走!VR技术带你沉浸式看展
LeetCode每日两题02:最长回文子串 (均1200道)
数据治理:走出数据孤岛
学习MySQL的第二天:SQL(基础篇)
leetcode 15. Sum of three numbers
用低代码如何搭建一套进销存管理系统(采购、销售、库存一体化管理)?
LeetCode Daily 2 Questions 02: Number of Palindromes (1200 each)
leetcode 17. Letter Combinations of Phone Numbers









