File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1+ // LongestCommonPrefix.swift
2+ // Created by 王玉朝 on 2019/6/14.
3+ // Copyright © 2019 王玉朝. All rights reserved.
4+
5+ class ValidParentheses {
6+ func isValid( _ s: String ) -> Bool {
7+ var stack = [ Character] ( )
8+
9+ for char in s {
10+ if char == " ( " || char == " [ " || char == " { " {
11+ stack. append ( char)
12+ } else if char == " ) " {
13+ guard stack. count != 0 && stack. removeLast ( ) == " ( " else {
14+ return false
15+ }
16+ } else if char == " ] " {
17+ guard stack. count != 0 && stack. removeLast ( ) == " [ " else {
18+ return false
19+ }
20+ } else if char == " } " {
21+ guard stack. count != 0 && stack. removeLast ( ) == " { " else {
22+ return false
23+ }
24+ }
25+ }
26+
27+ return stack. isEmpty
28+ }
29+ }
Original file line number Diff line number Diff line change 33| 参与成员 |
44| ------ |
55| [ hongqima] ( https://github.com/hotchner ) |
6- | [ Wang-yuchao ] ( https://github.com/Wang-yuchao ) |
6+ | [ wangyuchaogeek ] ( https://github.com/wangyuchaogeek ) |
77| [ ZQMei] ( https://github.com/ZQMei ) |
88| [ 新哥_会飞的猴子] ( https://github.com/CoderLiuJixin ) |
99
2828| 17 | [ 电话号码的字母组合] ( https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number ) | 中等 | | | | | |
2929| 18 | [ 四数之和] ( https://leetcode-cn.com/problems/4sum ) | 中等 | | | | | |
3030| 19 | [ 删除链表的倒数第N个节点] ( https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list ) | 中等 | | | | | |
31- | 20 | [ 有效的括号] ( https://leetcode-cn.com/problems/valid-parentheses ) | 简单 | | | | | |
31+ | 20 | [ 有效的括号] ( https://leetcode-cn.com/problems/valid-parentheses ) | 简单 | [ Swift ] ( 0020-有效的括号/Swift ) | | | | |
3232| 21 | [ 合并两个有序链表] ( https://leetcode-cn.com/problems/merge-two-sorted-lists ) | 简单 | | | | | |
3333| 22 | [ 括号生成] ( https://leetcode-cn.com/problems/generate-parentheses ) | 中等 | | | | | |
3434| 23 | [ 合并K个排序链表] ( https://leetcode-cn.com/problems/merge-k-sorted-lists ) | 困难 | | | | | |
You can’t perform that action at this time.
0 commit comments