File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
solution/0800-0899/0846.Hand of Straights Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -172,20 +172,20 @@ func isNStraightHand(hand []int, groupSize int) bool {
172
172
#### TypeScript
173
173
174
174
``` ts
175
- export function isNStraightHand(hand : number [], groupSize : number ) {
176
- const map: Record <number , number > = {};
177
-
175
+ function isNStraightHand(hand : number [], groupSize : number ) {
176
+ const cnt: Record <number , number > = {};
178
177
for (const i of hand ) {
179
- map [i ] = (map [i ] ?? 0 ) + 1 ;
178
+ cnt [i ] = (cnt [i ] ?? 0 ) + 1 ;
180
179
}
181
180
182
- const keys = Object .keys (map ).map (Number );
183
-
181
+ const keys = Object .keys (cnt ).map (Number );
184
182
for (const i of keys ) {
185
- while (map [i ]) {
183
+ while (cnt [i ]) {
186
184
for (let j = i ; j < groupSize + i ; j ++ ) {
187
- if (! map [j ]) return false ;
188
- map [j ]-- ;
185
+ if (! cnt [j ]) {
186
+ return false ;
187
+ }
188
+ cnt [j ]-- ;
189
189
}
190
190
}
191
191
}
You can’t perform that action at this time.
0 commit comments