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 @@ -163,20 +163,20 @@ func isNStraightHand(hand []int, groupSize int) bool {
163
163
#### TypeScript
164
164
165
165
``` ts
166
- export function isNStraightHand(hand : number [], groupSize : number ) {
167
- const map: Record <number , number > = {};
168
-
166
+ function isNStraightHand(hand : number [], groupSize : number ) {
167
+ const cnt: Record <number , number > = {};
169
168
for (const i of hand ) {
170
- map [i ] = (map [i ] ?? 0 ) + 1 ;
169
+ cnt [i ] = (cnt [i ] ?? 0 ) + 1 ;
171
170
}
172
171
173
- const keys = Object .keys (map ).map (Number );
174
-
172
+ const keys = Object .keys (cnt ).map (Number );
175
173
for (const i of keys ) {
176
- while (map [i ]) {
174
+ while (cnt [i ]) {
177
175
for (let j = i ; j < groupSize + i ; j ++ ) {
178
- if (! map [j ]) return false ;
179
- map [j ]-- ;
176
+ if (! cnt [j ]) {
177
+ return false ;
178
+ }
179
+ cnt [j ]-- ;
180
180
}
181
181
}
182
182
}
You can’t perform that action at this time.
0 commit comments