File tree Expand file tree Collapse file tree 6 files changed +80
-0
lines changed
3180.Maximum Total Reward Using Operations I
3181.Maximum Total Reward Using Operations II Expand file tree Collapse file tree 6 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -456,6 +456,21 @@ func maxTotalReward(rewardValues []int) int {
456
456
}
457
457
```
458
458
459
+ #### TypeScript
460
+
461
+ ``` ts
462
+ function maxTotalReward(rewardValues : number []): number {
463
+ rewardValues .sort ((a , b ) => a - b );
464
+ rewardValues = [... new Set (rewardValues )];
465
+ let f = 1n ;
466
+ for (const x of rewardValues ) {
467
+ const mask = (1n << BigInt (x )) - 1n ;
468
+ f = f | ((f & mask ) << BigInt (x ));
469
+ }
470
+ return f .toString (2 ).length - 1 ;
471
+ }
472
+ ```
473
+
459
474
<!-- tabs: end -->
460
475
461
476
<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -454,6 +454,21 @@ func maxTotalReward(rewardValues []int) int {
454
454
}
455
455
```
456
456
457
+ #### TypeScript
458
+
459
+ ``` ts
460
+ function maxTotalReward(rewardValues : number []): number {
461
+ rewardValues .sort ((a , b ) => a - b );
462
+ rewardValues = [... new Set (rewardValues )];
463
+ let f = 1n ;
464
+ for (const x of rewardValues ) {
465
+ const mask = (1n << BigInt (x )) - 1n ;
466
+ f = f | ((f & mask ) << BigInt (x ));
467
+ }
468
+ return f .toString (2 ).length - 1 ;
469
+ }
470
+ ```
471
+
457
472
<!-- tabs: end -->
458
473
459
474
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ function maxTotalReward ( rewardValues : number [ ] ) : number {
2
+ rewardValues . sort ( ( a , b ) => a - b ) ;
3
+ rewardValues = [ ...new Set ( rewardValues ) ] ;
4
+ let f = 1n ;
5
+ for ( const x of rewardValues ) {
6
+ const mask = ( 1n << BigInt ( x ) ) - 1n ;
7
+ f = f | ( ( f & mask ) << BigInt ( x ) ) ;
8
+ }
9
+ return f . toString ( 2 ) . length - 1 ;
10
+ }
Original file line number Diff line number Diff line change @@ -167,6 +167,21 @@ func maxTotalReward(rewardValues []int) int {
167
167
}
168
168
```
169
169
170
+ #### TypeScript
171
+
172
+ ``` ts
173
+ function maxTotalReward(rewardValues : number []): number {
174
+ rewardValues .sort ((a , b ) => a - b );
175
+ rewardValues = [... new Set (rewardValues )];
176
+ let f = 1n ;
177
+ for (const x of rewardValues ) {
178
+ const mask = (1n << BigInt (x )) - 1n ;
179
+ f = f | ((f & mask ) << BigInt (x ));
180
+ }
181
+ return f .toString (2 ).length - 1 ;
182
+ }
183
+ ```
184
+
170
185
<!-- tabs: end -->
171
186
172
187
<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -165,6 +165,21 @@ func maxTotalReward(rewardValues []int) int {
165
165
}
166
166
```
167
167
168
+ #### TypeScript
169
+
170
+ ``` ts
171
+ function maxTotalReward(rewardValues : number []): number {
172
+ rewardValues .sort ((a , b ) => a - b );
173
+ rewardValues = [... new Set (rewardValues )];
174
+ let f = 1n ;
175
+ for (const x of rewardValues ) {
176
+ const mask = (1n << BigInt (x )) - 1n ;
177
+ f = f | ((f & mask ) << BigInt (x ));
178
+ }
179
+ return f .toString (2 ).length - 1 ;
180
+ }
181
+ ```
182
+
168
183
<!-- tabs: end -->
169
184
170
185
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ function maxTotalReward ( rewardValues : number [ ] ) : number {
2
+ rewardValues . sort ( ( a , b ) => a - b ) ;
3
+ rewardValues = [ ...new Set ( rewardValues ) ] ;
4
+ let f = 1n ;
5
+ for ( const x of rewardValues ) {
6
+ const mask = ( 1n << BigInt ( x ) ) - 1n ;
7
+ f = f | ( ( f & mask ) << BigInt ( x ) ) ;
8
+ }
9
+ return f . toString ( 2 ) . length - 1 ;
10
+ }
You can’t perform that action at this time.
0 commit comments