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 f744bd3

Browse files
feat: add typescript solution to lc problem: No.2428
No.2428.Maximum Sum of an Hourglass
1 parent fd412e8 commit f744bd3

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

‎solution/2400-2499/2428.Maximum Sum of an Hourglass/README.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,22 @@ func max(a, b int) int {
161161
### **TypeScript**
162162

163163
```ts
164-
164+
function maxSum(grid: number[][]): number {
165+
const m = grid.length, n = grid[0].length;
166+
let threeSum = Array.from({ length: m }, () => new Array(n - 2).fill(0));
167+
for (let i = 0; i < m; i++) {
168+
for (let j = 1; j < n - 1; j++) {
169+
threeSum[i][j - 1] = grid[i][j - 1] + grid[i][j] + grid[i][j + 1];
170+
}
171+
}
172+
let ans = 0;
173+
for (let i = 1; i < m - 1; i++) {
174+
for (let j = 1; j < n - 1; j++) {
175+
ans = Math.max(ans, threeSum[i - 1][j - 1] + grid[i][j] + threeSum[i + 1][j - 1]);
176+
}
177+
}
178+
return ans;
179+
};
165180
```
166181

167182
### **...**

‎solution/2400-2499/2428.Maximum Sum of an Hourglass/README_EN.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,22 @@ func max(a, b int) int {
147147
### **TypeScript**
148148

149149
```ts
150-
150+
function maxSum(grid: number[][]): number {
151+
const m = grid.length, n = grid[0].length;
152+
let threeSum = Array.from({ length: m }, () => new Array(n - 2).fill(0));
153+
for (let i = 0; i < m; i++) {
154+
for (let j = 1; j < n - 1; j++) {
155+
threeSum[i][j - 1] = grid[i][j - 1] + grid[i][j] + grid[i][j + 1];
156+
}
157+
}
158+
let ans = 0;
159+
for (let i = 1; i < m - 1; i++) {
160+
for (let j = 1; j < n - 1; j++) {
161+
ans = Math.max(ans, threeSum[i - 1][j - 1] + grid[i][j] + threeSum[i + 1][j - 1]);
162+
}
163+
}
164+
return ans;
165+
};
151166
```
152167

153168
### **...**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function maxSum(grid: number[][]): number {
2+
const m = grid.length, n = grid[0].length;
3+
let threeSum = Array.from({ length: m }, () => new Array(n - 2).fill(0));
4+
for (let i = 0; i < m; i++) {
5+
for (let j = 1; j < n - 1; j++) {
6+
threeSum[i][j - 1] = grid[i][j - 1] + grid[i][j] + grid[i][j + 1];
7+
}
8+
}
9+
let ans = 0;
10+
for (let i = 1; i < m - 1; i++) {
11+
for (let j = 1; j < n - 1; j++) {
12+
ans = Math.max(ans, threeSum[i - 1][j - 1] + grid[i][j] + threeSum[i + 1][j - 1]);
13+
}
14+
}
15+
return ans;
16+
};

0 commit comments

Comments
(0)

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