[swift] LeetCode 20. Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid.
The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.
func isValid(_ s: String) -> Bool {var stack = [Character](), b = truefunc compare(_ c: Character) -> Bool {guard let t = stack.popLast() else { return false }return (c == ")" && t == "(") || (c == "]" && t == "[" ) || (c == "}" && t == "{")}loop: for c in s {switch c {case "(", "[", "{":stack.append(c)default:b = compare(c)if !b { break loop }}}return b && stack.isEmpty
}
[swift] LeetCode 20. Valid Parentheses相关推荐
- LeetCode: 20. Valid Parentheses
0509第1题(虽然是08做的,但这会已经09了) 题目 Given a string containing just the characters '(', ')', '{', '}', '[' a ...
- [LeetCode]--20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- LeetCode 20 Valid Parentheses (C++)
问题: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...
- LeetCode 20. Valid Parentheses(c++)
利用栈的操作,遇到"(","[","{"即进栈,遇到")","]","}"判断是 ...
- LeetCode Longest Valid Parentheses
原题链接在这里:https://leetcode.com/problems/longest-valid-parentheses/ 题目: Given a string containing just ...
- LeetCode 20. Valid Parentheses--笔试题--Python解法
题目地址:Valid Parentheses - LeetCode Given a string containing just the characters '(', ')', '{', '}', ...
- 最长有效括号子串长度 c语言,LeetCode: Longest Valid Parentheses (求最长有效匹配括号子串的长度)...
题目描述: Given a string containing just the characters'(' and')', find the length of the longest valid ...
- Leetcode: Longest Valid Parentheses
Question Given a string containing just the characters '(' and ')', find the length of the longest v ...
- LeetCode 20. Valid Parenthese
题目: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...
最新文章
- 《剑指Offer》题目:树的子结构
- iOS开发-项目的完整重命名方法,图文教程。
- java高并发(六)线程安全性
- 滤波器开发之一:基于算数平均的平滑滤波器
- uburntu在不能自动获取网络时的联网设置
- 普元BPS:唯一零错误的流程平台
- 拓端tecdat|matlab使用长短期记忆(LSTM)神经网络对序列数据进行分类
- 一个完整的测试计划模板
- 华为ipop使用教程_华为内部远程工具——IPOP,了解一下
- 参考文献格式字号字体_论文字体字号格式要求是什么?
- G-Biosciences Tube-O-DIALYZER系列透析管方案
- vue 直接访问静态图片_在使用vue中实现本地静态图片路径(详细教程)
- C练题笔记之:Leetcode-1427. 字符串的左右移
- winform 读取用户控件的变量_VS2005winform程序中获取用户控件的值
- 打造一张万能Windows安装盘(转)
- 【MapSqlParameterSource】映射数据源官方API介绍
- e480换高分屏_四世同堂,12年一轮回,再赏ThinkPad机型
- [歌词]《一花依世界》《君がいる世界へ》歌词假名罗马音(上标注音版)
- PDF编辑工具怎么为PDF文件添加页码
- 导航报错SetDestination() can only be called on an active agent that has been placed on a NavMesh