Skip to content

Commit 6292326

Browse files
authored
feat: add swift implementation to lcof problem: No.61 (#2953)
1 parent 305ae08 commit 6292326

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lcof/面试题61. 扑克牌中的顺子/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,30 @@ public class Solution {
228228
}
229229
```
230230

231+
#### Swift
232+
233+
```swift
234+
class Solution {
235+
func isStraight(_ nums: [Int]) -> Bool {
236+
var vis = Array(repeating: false, count: 14)
237+
var mi = 20, mx = -1
238+
for x in nums {
239+
if x == 0 {
240+
continue
241+
}
242+
if vis[x] {
243+
return false
244+
}
245+
vis[x] = true
246+
mi = min(mi, x)
247+
mx = max(mx, x)
248+
}
249+
return mx - mi <= 4
250+
}
251+
}
252+
253+
```
254+
231255
<!-- tabs:end -->
232256

233257
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
func isStraight(_ nums: [Int]) -> Bool {
3+
var vis = Array(repeating: false, count: 14)
4+
var mi = 20, mx = -1
5+
for x in nums {
6+
if x == 0 {
7+
continue
8+
}
9+
if vis[x] {
10+
return false
11+
}
12+
vis[x] = true
13+
mi = min(mi, x)
14+
mx = max(mx, x)
15+
}
16+
return mx - mi <= 4
17+
}
18+
}

0 commit comments

Comments
 (0)