diff --git a/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README.md b/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README.md index 059ddcce253d6..d65fd14842d73 100644 --- a/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README.md +++ b/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README.md @@ -456,6 +456,21 @@ func maxTotalReward(rewardValues []int) int { } ``` +#### TypeScript + +```ts +function maxTotalReward(rewardValues: number[]): number { + rewardValues.sort((a, b) => a - b); + rewardValues = [...new Set(rewardValues)]; + let f = 1n; + for (const x of rewardValues) { + const mask = (1n << BigInt(x)) - 1n; + f = f | ((f & mask) << BigInt(x)); + } + return f.toString(2).length - 1; +} +``` + diff --git a/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README_EN.md b/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README_EN.md index 8a39b4d1a95b0..c164c08fb9efa 100644 --- a/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README_EN.md +++ b/solution/3100-3199/3180.Maximum Total Reward Using Operations I/README_EN.md @@ -454,6 +454,21 @@ func maxTotalReward(rewardValues []int) int { } ``` +#### TypeScript + +```ts +function maxTotalReward(rewardValues: number[]): number { + rewardValues.sort((a, b) => a - b); + rewardValues = [...new Set(rewardValues)]; + let f = 1n; + for (const x of rewardValues) { + const mask = (1n << BigInt(x)) - 1n; + f = f | ((f & mask) << BigInt(x)); + } + return f.toString(2).length - 1; +} +``` + diff --git a/solution/3100-3199/3180.Maximum Total Reward Using Operations I/Solution3.ts b/solution/3100-3199/3180.Maximum Total Reward Using Operations I/Solution3.ts new file mode 100644 index 0000000000000..6f9b45b9a2396 --- /dev/null +++ b/solution/3100-3199/3180.Maximum Total Reward Using Operations I/Solution3.ts @@ -0,0 +1,10 @@ +function maxTotalReward(rewardValues: number[]): number { + rewardValues.sort((a, b) => a - b); + rewardValues = [...new Set(rewardValues)]; + let f = 1n; + for (const x of rewardValues) { + const mask = (1n << BigInt(x)) - 1n; + f = f | ((f & mask) << BigInt(x)); + } + return f.toString(2).length - 1; +} diff --git a/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README.md b/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README.md index 94676efc4b914..4b83543ce3bb3 100644 --- a/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README.md +++ b/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README.md @@ -167,6 +167,21 @@ func maxTotalReward(rewardValues []int) int { } ``` +#### TypeScript + +```ts +function maxTotalReward(rewardValues: number[]): number { + rewardValues.sort((a, b) => a - b); + rewardValues = [...new Set(rewardValues)]; + let f = 1n; + for (const x of rewardValues) { + const mask = (1n << BigInt(x)) - 1n; + f = f | ((f & mask) << BigInt(x)); + } + return f.toString(2).length - 1; +} +``` + diff --git a/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README_EN.md b/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README_EN.md index 358708a1eff5b..765a9beeb5e37 100644 --- a/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README_EN.md +++ b/solution/3100-3199/3181.Maximum Total Reward Using Operations II/README_EN.md @@ -165,6 +165,21 @@ func maxTotalReward(rewardValues []int) int { } ``` +#### TypeScript + +```ts +function maxTotalReward(rewardValues: number[]): number { + rewardValues.sort((a, b) => a - b); + rewardValues = [...new Set(rewardValues)]; + let f = 1n; + for (const x of rewardValues) { + const mask = (1n << BigInt(x)) - 1n; + f = f | ((f & mask) << BigInt(x)); + } + return f.toString(2).length - 1; +} +``` + diff --git a/solution/3100-3199/3181.Maximum Total Reward Using Operations II/Solution.ts b/solution/3100-3199/3181.Maximum Total Reward Using Operations II/Solution.ts new file mode 100644 index 0000000000000..6f9b45b9a2396 --- /dev/null +++ b/solution/3100-3199/3181.Maximum Total Reward Using Operations II/Solution.ts @@ -0,0 +1,10 @@ +function maxTotalReward(rewardValues: number[]): number { + rewardValues.sort((a, b) => a - b); + rewardValues = [...new Set(rewardValues)]; + let f = 1n; + for (const x of rewardValues) { + const mask = (1n << BigInt(x)) - 1n; + f = f | ((f & mask) << BigInt(x)); + } + return f.toString(2).length - 1; +}