给你一个 n x n 的二维数组 grid,它包含范围 [0, n2 - 1] 内的不重复元素。
n x n
grid
[0, n2 - 1]
实现 neighborSum 类:
neighborSum
neighborSum(int [][]grid)
int adjacentSum(int value)
value
int diagonalSum(int value)
示例 1:
输入:
["neighborSum", "adjacentSum", "adjacentSum", "diagonalSum", "diagonalSum"]
[[[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [1], [4], [4], [8]]
输出: [null, 6, 16, 16, 4]
解释:
示例 2:
["neighborSum", "adjacentSum", "diagonalSum"]
[[[[1, 2, 0, 3], [4, 7, 15, 6], [8, 9, 10, 11], [12, 13, 14, 5]]], [15], [9]]
输出: [null, 23, 45]
提示:
3 <= n == grid.length == grid[0].length <= 10
0 <= grid[i][j] <= n2 - 1
grid[i][j]
adjacentSum
diagonalSum
2 * n2
(i, j)