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

Commit cf78167

Browse files
feat: add solutions to lc problems: No.3180,3181 (doocs#3671)
* No.3180.Maximum Total Reward Using Operations I * No.3181.Maximum Total Reward Using Operations II
1 parent 059ff27 commit cf78167

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

‎solution/3100-3199/3180.Maximum Total Reward Using Operations I/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,21 @@ func maxTotalReward(rewardValues []int) int {
456456
}
457457
```
458458

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+
459474
<!-- tabs:end -->
460475

461476
<!-- solution:end -->

‎solution/3100-3199/3180.Maximum Total Reward Using Operations I/README_EN.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,21 @@ func maxTotalReward(rewardValues []int) int {
454454
}
455455
```
456456

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+
457472
<!-- tabs:end -->
458473

459474
<!-- solution:end -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

‎solution/3100-3199/3181.Maximum Total Reward Using Operations II/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ func maxTotalReward(rewardValues []int) int {
167167
}
168168
```
169169

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+
170185
<!-- tabs:end -->
171186

172187
<!-- solution:end -->

‎solution/3100-3199/3181.Maximum Total Reward Using Operations II/README_EN.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ func maxTotalReward(rewardValues []int) int {
165165
}
166166
```
167167

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+
168183
<!-- tabs:end -->
169184

170185
<!-- solution:end -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /