diff --git a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md index bbcd842bc17c7..d4c87dcd6644f 100644 --- a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md +++ b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README.md @@ -177,4 +177,30 @@ function partitionArray(nums: number[], k: number): number { + + +### Solution 2 + + + +#### TypeScript + +```ts +function partitionArray(nums: number[], k: number): number { + let c = 0; + + while (nums.length) { + const max = Math.max(...nums) - k; + nums = nums.filter(x => x < max); + c++; + } + + return c; +} +``` + + + + + diff --git a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md index bbf4c0002ffcb..17804b9b29f14 100644 --- a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md +++ b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/README_EN.md @@ -171,4 +171,30 @@ function partitionArray(nums: number[], k: number): number { + + +### Solution 2 + + + +#### TypeScript + +```ts +function partitionArray(nums: number[], k: number): number { + let c = 0; + + while (nums.length) { + const max = Math.max(...nums) - k; + nums = nums.filter(x => x < max); + c++; + } + + return c; +} +``` + + + + + diff --git a/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/Solution2.ts b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/Solution2.ts new file mode 100644 index 0000000000000..20a53d38d9830 --- /dev/null +++ b/solution/2200-2299/2294.Partition Array Such That Maximum Difference Is K/Solution2.ts @@ -0,0 +1,11 @@ +function partitionArray(nums: number[], k: number): number { + let c = 0; + + while (nums.length) { + const max = Math.max(...nums) - k; + nums = nums.filter(x => x < max); + c++; + } + + return c; +}