Skip to content

chore: update solutions to lc problem: No.3242 #3733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions solution/3200-3299/3242.Design Neighbor Sum Service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ tags:
#### Python3

```python
class neighborSum:
class NeighborSum:

def __init__(self, grid: List[List[int]]):
self.grid = grid
Expand All @@ -135,21 +135,21 @@ class neighborSum:
return self.cal(value, 1)


# Your neighborSum object will be instantiated and called as such:
# obj = neighborSum(grid)
# Your NeighborSum object will be instantiated and called as such:
# obj = NeighborSum(grid)
# param_1 = obj.adjacentSum(value)
# param_2 = obj.diagonalSum(value)
```

#### Java

```java
class neighborSum {
class NeighborSum {
private int[][] grid;
private final Map<Integer, int[]> d = new HashMap<>();
private final int[][] dirs = {{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}};

public neighborSum(int[][] grid) {
public NeighborSum(int[][] grid) {
this.grid = grid;
int m = grid.length, n = grid[0].length;
for (int i = 0; i < m; ++i) {
Expand Down Expand Up @@ -181,8 +181,8 @@ class neighborSum {
}

/**
* Your neighborSum object will be instantiated and called as such:
* neighborSum obj = new neighborSum(grid);
* Your NeighborSum object will be instantiated and called as such:
* NeighborSum obj = new NeighborSum(grid);
* int param_1 = obj.adjacentSum(value);
* int param_2 = obj.diagonalSum(value);
*/
Expand All @@ -191,9 +191,9 @@ class neighborSum {
#### C++

```cpp
class neighborSum {
class NeighborSum {
public:
neighborSum(vector<vector<int>>& grid) {
NeighborSum(vector<vector<int>>& grid) {
this->grid = grid;
int m = grid.size(), n = grid[0].size();
for (int i = 0; i < m; ++i) {
Expand Down Expand Up @@ -230,8 +230,8 @@ private:
};

/**
* Your neighborSum object will be instantiated and called as such:
* neighborSum* obj = new neighborSum(grid);
* Your NeighborSum object will be instantiated and called as such:
* NeighborSum* obj = new NeighborSum(grid);
* int param_1 = obj->adjacentSum(value);
* int param_2 = obj->diagonalSum(value);
*/
Expand All @@ -240,32 +240,32 @@ private:
#### Go

```go
type neighborSum struct {
type NeighborSum struct {
grid [][]int
d map[int][2]int
dirs [2][5]int
}

func Constructor(grid [][]int) neighborSum {
func Constructor(grid [][]int) NeighborSum {
d := map[int][2]int{}
for i, row := range grid {
for j, x := range row {
d[x] = [2]int{i, j}
}
}
dirs := [2][5]int{{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}}
return neighborSum{grid, d, dirs}
return NeighborSum{grid, d, dirs}
}

func (this *neighborSum) AdjacentSum(value int) int {
func (this *NeighborSum) AdjacentSum(value int) int {
return this.cal(value, 0)
}

func (this *neighborSum) DiagonalSum(value int) int {
func (this *NeighborSum) DiagonalSum(value int) int {
return this.cal(value, 1)
}

func (this *neighborSum) cal(value, k int) int {
func (this *NeighborSum) cal(value, k int) int {
p := this.d[value]
s := 0
for q := 0; q < 4; q++ {
Expand All @@ -278,7 +278,7 @@ func (this *neighborSum) cal(value, k int) int {
}

/**
* Your neighborSum object will be instantiated and called as such:
* Your NeighborSum object will be instantiated and called as such:
* obj := Constructor(grid);
* param_1 := obj.AdjacentSum(value);
* param_2 := obj.DiagonalSum(value);
Expand All @@ -288,7 +288,7 @@ func (this *neighborSum) cal(value, k int) int {
#### TypeScript

```ts
class neighborSum {
class NeighborSum {
private grid: number[][];
private d: Map<number, [number, number]> = new Map();
private dirs: number[][] = [
Expand Down Expand Up @@ -326,8 +326,8 @@ class neighborSum {
}

/**
* Your neighborSum object will be instantiated and called as such:
* var obj = new neighborSum(grid)
* Your NeighborSum object will be instantiated and called as such:
* var obj = new NeighborSum(grid)
* var param_1 = obj.adjacentSum(value)
* var param_2 = obj.diagonalSum(value)
*/
Expand Down
42 changes: 21 additions & 21 deletions solution/3200-3299/3242.Design Neighbor Sum Service/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ In terms of time complexity, initializing the hash table has a time complexity o
#### Python3

```python
class neighborSum:
class NeighborSum:

def __init__(self, grid: List[List[int]]):
self.grid = grid
Expand All @@ -133,21 +133,21 @@ class neighborSum:
return self.cal(value, 1)


# Your neighborSum object will be instantiated and called as such:
# obj = neighborSum(grid)
# Your NeighborSum object will be instantiated and called as such:
# obj = NeighborSum(grid)
# param_1 = obj.adjacentSum(value)
# param_2 = obj.diagonalSum(value)
```

#### Java

```java
class neighborSum {
class NeighborSum {
private int[][] grid;
private final Map<Integer, int[]> d = new HashMap<>();
private final int[][] dirs = {{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}};

public neighborSum(int[][] grid) {
public NeighborSum(int[][] grid) {
this.grid = grid;
int m = grid.length, n = grid[0].length;
for (int i = 0; i < m; ++i) {
Expand Down Expand Up @@ -179,8 +179,8 @@ class neighborSum {
}

/**
* Your neighborSum object will be instantiated and called as such:
* neighborSum obj = new neighborSum(grid);
* Your NeighborSum object will be instantiated and called as such:
* NeighborSum obj = new NeighborSum(grid);
* int param_1 = obj.adjacentSum(value);
* int param_2 = obj.diagonalSum(value);
*/
Expand All @@ -189,9 +189,9 @@ class neighborSum {
#### C++

```cpp
class neighborSum {
class NeighborSum {
public:
neighborSum(vector<vector<int>>& grid) {
NeighborSum(vector<vector<int>>& grid) {
this->grid = grid;
int m = grid.size(), n = grid[0].size();
for (int i = 0; i < m; ++i) {
Expand Down Expand Up @@ -228,8 +228,8 @@ private:
};

/**
* Your neighborSum object will be instantiated and called as such:
* neighborSum* obj = new neighborSum(grid);
* Your NeighborSum object will be instantiated and called as such:
* NeighborSum* obj = new NeighborSum(grid);
* int param_1 = obj->adjacentSum(value);
* int param_2 = obj->diagonalSum(value);
*/
Expand All @@ -238,32 +238,32 @@ private:
#### Go

```go
type neighborSum struct {
type NeighborSum struct {
grid [][]int
d map[int][2]int
dirs [2][5]int
}

func Constructor(grid [][]int) neighborSum {
func Constructor(grid [][]int) NeighborSum {
d := map[int][2]int{}
for i, row := range grid {
for j, x := range row {
d[x] = [2]int{i, j}
}
}
dirs := [2][5]int{{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}}
return neighborSum{grid, d, dirs}
return NeighborSum{grid, d, dirs}
}

func (this *neighborSum) AdjacentSum(value int) int {
func (this *NeighborSum) AdjacentSum(value int) int {
return this.cal(value, 0)
}

func (this *neighborSum) DiagonalSum(value int) int {
func (this *NeighborSum) DiagonalSum(value int) int {
return this.cal(value, 1)
}

func (this *neighborSum) cal(value, k int) int {
func (this *NeighborSum) cal(value, k int) int {
p := this.d[value]
s := 0
for q := 0; q < 4; q++ {
Expand All @@ -276,7 +276,7 @@ func (this *neighborSum) cal(value, k int) int {
}

/**
* Your neighborSum object will be instantiated and called as such:
* Your NeighborSum object will be instantiated and called as such:
* obj := Constructor(grid);
* param_1 := obj.AdjacentSum(value);
* param_2 := obj.DiagonalSum(value);
Expand All @@ -286,7 +286,7 @@ func (this *neighborSum) cal(value, k int) int {
#### TypeScript

```ts
class neighborSum {
class NeighborSum {
private grid: number[][];
private d: Map<number, [number, number]> = new Map();
private dirs: number[][] = [
Expand Down Expand Up @@ -324,8 +324,8 @@ class neighborSum {
}

/**
* Your neighborSum object will be instantiated and called as such:
* var obj = new neighborSum(grid)
* Your NeighborSum object will be instantiated and called as such:
* var obj = new NeighborSum(grid)
* var param_1 = obj.adjacentSum(value)
* var param_2 = obj.diagonalSum(value)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class neighborSum {
class NeighborSum {
public:
neighborSum(vector<vector<int>>& grid) {
NeighborSum(vector<vector<int>>& grid) {
this->grid = grid;
int m = grid.size(), n = grid[0].size();
for (int i = 0; i < m; ++i) {
Expand Down Expand Up @@ -37,8 +37,8 @@ class neighborSum {
};

/**
* Your neighborSum object will be instantiated and called as such:
* neighborSum* obj = new neighborSum(grid);
* Your NeighborSum object will be instantiated and called as such:
* NeighborSum* obj = new NeighborSum(grid);
* int param_1 = obj->adjacentSum(value);
* int param_2 = obj->diagonalSum(value);
*/
14 changes: 7 additions & 7 deletions solution/3200-3299/3242.Design Neighbor Sum Service/Solution.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
type neighborSum struct {
type NeighborSum struct {
grid [][]int
d map[int][2]int
dirs [2][5]int
}

func Constructor(grid [][]int) neighborSum {
func Constructor(grid [][]int) NeighborSum {
d := map[int][2]int{}
for i, row := range grid {
for j, x := range row {
d[x] = [2]int{i, j}
}
}
dirs := [2][5]int{{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}}
return neighborSum{grid, d, dirs}
return NeighborSum{grid, d, dirs}
}

func (this *neighborSum) AdjacentSum(value int) int {
func (this *NeighborSum) AdjacentSum(value int) int {
return this.cal(value, 0)
}

func (this *neighborSum) DiagonalSum(value int) int {
func (this *NeighborSum) DiagonalSum(value int) int {
return this.cal(value, 1)
}

func (this *neighborSum) cal(value, k int) int {
func (this *NeighborSum) cal(value, k int) int {
p := this.d[value]
s := 0
for q := 0; q < 4; q++ {
Expand All @@ -36,7 +36,7 @@ func (this *neighborSum) cal(value, k int) int {
}

/**
* Your neighborSum object will be instantiated and called as such:
* Your NeighborSum object will be instantiated and called as such:
* obj := Constructor(grid);
* param_1 := obj.AdjacentSum(value);
* param_2 := obj.DiagonalSum(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class neighborSum {
class NeighborSum {
private int[][] grid;
private final Map<Integer, int[]> d = new HashMap<>();
private final int[][] dirs = {{-1, 0, 1, 0, -1}, {-1, 1, 1, -1, -1}};

public neighborSum(int[][] grid) {
public NeighborSum(int[][] grid) {
this.grid = grid;
int m = grid.length, n = grid[0].length;
for (int i = 0; i < m; ++i) {
Expand Down Expand Up @@ -35,8 +35,8 @@ private int cal(int value, int k) {
}

/**
* Your neighborSum object will be instantiated and called as such:
* neighborSum obj = new neighborSum(grid);
* Your NeighborSum object will be instantiated and called as such:
* NeighborSum obj = new NeighborSum(grid);
* int param_1 = obj.adjacentSum(value);
* int param_2 = obj.diagonalSum(value);
*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class neighborSum:
class NeighborSum:

def __init__(self, grid: List[List[int]]):
self.grid = grid
Expand All @@ -24,7 +24,7 @@ def diagonalSum(self, value: int) -> int:
return self.cal(value, 1)


# Your neighborSum object will be instantiated and called as such:
# obj = neighborSum(grid)
# Your NeighborSum object will be instantiated and called as such:
# obj = NeighborSum(grid)
# param_1 = obj.adjacentSum(value)
# param_2 = obj.diagonalSum(value)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class neighborSum {
class NeighborSum {
private grid: number[][];
private d: Map<number, [number, number]> = new Map();
private dirs: number[][] = [
Expand Down Expand Up @@ -36,8 +36,8 @@ class neighborSum {
}

/**
* Your neighborSum object will be instantiated and called as such:
* var obj = new neighborSum(grid)
* Your NeighborSum object will be instantiated and called as such:
* var obj = new NeighborSum(grid)
* var param_1 = obj.adjacentSum(value)
* var param_2 = obj.diagonalSum(value)
*/
Loading