From 6a5aad35f5e033c33998eb47288ad9b5997e2fa9 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Tue, 25 Jul 2023 21:50:46 +0800 Subject: [PATCH] feat: add ts solution to lc problem: No.2500 --- .../README.md | 21 +++++++++++++++++++ .../README_EN.md | 21 +++++++++++++++++++ .../Solution.ts | 16 ++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.ts diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md index 8c2a45adb86ea..69d54b769f55f 100644 --- a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md @@ -175,6 +175,27 @@ impl Solution { } ``` +### **TypeScript** + +```ts +function deleteGreatestValue(grid: number[][]): number { + for (const row of grid) { + row.sort((a, b) => a - b); + } + + let ans = 0; + for (let j = 0; j < grid[0].length; ++j) { + let t = 0; + for (let i = 0; i < grid.length; ++i) { + t = Math.max(t, grid[i][j]); + } + ans += t; + } + + return ans; +} +``` + ### **...** ``` diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md index 4814010e5addf..803514df2d820 100644 --- a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md @@ -153,6 +153,27 @@ impl Solution { } ``` +### **TypeScript** + +```ts +function deleteGreatestValue(grid: number[][]): number { + for (const row of grid) { + row.sort((a, b) => a - b); + } + + let ans = 0; + for (let j = 0; j < grid[0].length; ++j) { + let t = 0; + for (let i = 0; i < grid.length; ++i) { + t = Math.max(t, grid[i][j]); + } + ans += t; + } + + return ans; +} +``` + ### **...** ``` diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.ts b/solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.ts new file mode 100644 index 0000000000000..1d4518663c255 --- /dev/null +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.ts @@ -0,0 +1,16 @@ +function deleteGreatestValue(grid: number[][]): number { + for (const row of grid) { + row.sort((a, b) => a - b); + } + + let ans = 0; + for (let j = 0; j < grid[0].length; ++j) { + let t = 0; + for (let i = 0; i < grid.length; ++i) { + t = Math.max(t, grid[i][j]); + } + ans += t; + } + + return ans; +}