Skip to content

Commit faf07e5

Browse files
committed
feat: update golang solution to lcof problem: No.61
1 parent 78f7e50 commit faf07e5

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

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

+35
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,41 @@ public:
142142

143143
```
144144

145+
### **Go**
146+
147+
```go
148+
func isStraight(nums []int) bool {
149+
m := make(map[int]struct{})
150+
mi, ma := 14, 0
151+
for _, num := range nums {
152+
if num == 0 {
153+
continue
154+
}
155+
if _, exist := m[num]; exist {
156+
return false
157+
}
158+
mi = min(mi, num)
159+
ma = max(ma, num)
160+
m[num] = struct{}{}
161+
}
162+
return ma-mi < 5
163+
}
164+
165+
func max(x, y int) int {
166+
if x > y {
167+
return x
168+
}
169+
return y
170+
}
171+
172+
func min(x, y int) int {
173+
if x < y {
174+
return x
175+
}
176+
return y
177+
}
178+
```
179+
145180
### **...**
146181

147182
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
func isStraight(nums []int) bool {
2+
m := make(map[int]struct{})
3+
mi, ma := 14, 0
4+
for _, num := range nums {
5+
if num == 0 {
6+
continue
7+
}
8+
if _, exist := m[num]; exist {
9+
return false
10+
}
11+
mi = min(mi, num)
12+
ma = max(ma, num)
13+
m[num] = struct{}{}
14+
}
15+
return ma-mi < 5
16+
}
17+
18+
func max(x, y int) int {
19+
if x > y {
20+
return x
21+
}
22+
return y
23+
}
24+
25+
func min(x, y int) int {
26+
if x < y {
27+
return x
28+
}
29+
return y
30+
}

0 commit comments

Comments
 (0)