Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd25bff8

Browse files
authored
Merge pull requestneetcode-gh#1939 from kkr2/feat/0846-hand-of-straights.go
Create 0846-hand-of-straights.go
2 parentsc725f43 +ec779c5 commitd25bff8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

‎go/0846-hand-of-straights.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
funcisNStraightHand(hand []int,groupSizeint)bool {
2+
3+
iflen(hand)%groupSize!=0 {
4+
returnfalse
5+
}
6+
7+
countMap:=make(map[int]int)
8+
9+
for_,num:=rangehand {
10+
countMap[num]++
11+
}
12+
13+
varminHeap []int
14+
15+
foruniqueNum,_:=rangecountMap {
16+
minHeap=append(minHeap,uniqueNum)
17+
}
18+
19+
sort.Ints(minHeap)
20+
21+
forlen(minHeap)!=0 {
22+
first:=minHeap[0]
23+
24+
fori:=first;i<groupSize+first;i++ {
25+
if_,ok:=countMap[i];!ok {
26+
returnfalse
27+
}
28+
29+
countMap[i]--
30+
val:=countMap[i]
31+
32+
ifval==0 {
33+
ifi!=minHeap[0] {
34+
returnfalse
35+
}
36+
37+
minHeap=minHeap[1:]
38+
}
39+
40+
}
41+
42+
}
43+
returntrue
44+
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp