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相关推荐

  1. LeetCode: 20. Valid Parentheses

    0509第1题(虽然是08做的,但这会已经09了) 题目 Given a string containing just the characters '(', ')', '{', '}', '[' a ...

  2. [LeetCode]--20. Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  3. LeetCode 20 Valid Parentheses (C++)

    问题: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...

  4. LeetCode 20. Valid Parentheses(c++)

    利用栈的操作,遇到"(","[","{"即进栈,遇到")","]","}"判断是 ...

  5. LeetCode Longest Valid Parentheses

    原题链接在这里:https://leetcode.com/problems/longest-valid-parentheses/ 题目: Given a string containing just ...

  6. LeetCode 20. Valid Parentheses--笔试题--Python解法

    题目地址:Valid Parentheses - LeetCode Given a string containing just the characters '(', ')', '{', '}', ...

  7. 最长有效括号子串长度 c语言,LeetCode: Longest Valid Parentheses (求最长有效匹配括号子串的长度)...

    题目描述: Given a string containing just the characters'(' and')', find the length of the longest valid ...

  8. Leetcode: Longest Valid Parentheses

    Question Given a string containing just the characters '(' and ')', find the length of the longest v ...

  9. LeetCode 20. Valid Parenthese

    题目: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...

最新文章

  1. 《剑指Offer》题目:树的子结构
  2. iOS开发-项目的完整重命名方法,图文教程。
  3. java高并发(六)线程安全性
  4. 滤波器开发之一:基于算数平均的平滑滤波器
  5. uburntu在不能自动获取网络时的联网设置
  6. 普元BPS:唯一零错误的流程平台
  7. 拓端tecdat|matlab使用长短期记忆(LSTM)神经网络对序列数据进行分类
  8. 一个完整的测试计划模板
  9. 华为ipop使用教程_华为内部远程工具——IPOP,了解一下
  10. 参考文献格式字号字体_论文字体字号格式要求是什么?
  11. G-Biosciences Tube-O-DIALYZER系列透析管方案
  12. vue 直接访问静态图片_在使用vue中实现本地静态图片路径(详细教程)
  13. C练题笔记之:Leetcode-1427. 字符串的左右移
  14. winform 读取用户控件的变量_VS2005winform程序中获取用户控件的值
  15. 打造一张万能Windows安装盘(转)
  16. 【MapSqlParameterSource】映射数据源官方API介绍
  17. e480换高分屏_四世同堂,12年一轮回,再赏ThinkPad机型
  18. [歌词]《一花依世界》《君がいる世界へ》歌词假名罗马音(上标注音版)
  19. PDF编辑工具怎么为PDF文件添加页码
  20. 导航报错SetDestination() can only be called on an active agent that has been placed on a NavMesh

热门文章

  1. android窗口泄漏
  2. 万能日志数据收集器 Fluentd - 每天5分钟玩转 Docker 容器技术(91)
  3. mysql启动找不见socket
  4. [翻译] PPDragDropBadgeView
  5. Matlab中的函数句柄@
  6. 局部临时表 全局临时表 表变量
  7. [linux] mtu查看设置
  8. 投资大鳄摩根士丹利成Accellion FTA 服务器被黑事件的又一个受害者
  9. 如何保护 IT 基础设施的安全?谷歌给出了500页的答案
  10. 谷歌喊话三星:别再搞 Linux 内核代码了,安卓安全也不保了