Movatterモバイル変換


[0]ホーム

URL:


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

Commitf099aa0

Browse files
author
Sathish Babu
committed
✨ Added solution to 661
1 parenta276ef4 commitf099aa0

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

‎src/0661.Image-Smoother/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
**Example 1:**
99

1010
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
11+
Input:
12+
[[1,1,1],
13+
[1,0,1],
14+
[1,1,1]]
15+
Output:
16+
[[0, 0, 0],
17+
[0, 0, 0],
18+
[0, 0, 0]]
1319
```
1420

1521
##题意

‎src/0661.Image-Smoother/Solution.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(M [][]int) [][]int {
4+
m,n:=len(M),len(M[0])
5+
N:=make([][]int,m)
6+
fori:=rangeN {
7+
N[i]=make([]int,n)
8+
}
9+
fori:=0;i<m;i++ {
10+
forj:=0;j<n;j++ {
11+
N[i][j]=getSurrounding(M,i,j,m,n)
12+
}
13+
}
14+
returnN
15+
}
16+
17+
funcgetSurrounding(M [][]int,i,j,m,nint)int {
18+
total,c:=M[i][j],1
19+
ifi-1>=0 {
20+
total+=M[i-1][j]
21+
c++
22+
ifj-1>=0 {
23+
total+=M[i-1][j-1]
24+
c++
25+
}
26+
ifj+1<n {
27+
total+=M[i-1][j+1]
28+
c++
29+
}
30+
}
31+
ifi+1<m {
32+
total+=M[i+1][j]
33+
c++
34+
ifj-1>=0 {
35+
total+=M[i+1][j-1]
36+
c++
37+
}
38+
ifj+1<n {
39+
total+=M[i+1][j+1]
40+
c++
41+
}
42+
}
43+
ifj-1>=0 {
44+
total+=M[i][j-1]
45+
c++
46+
}
47+
ifj+1<n {
48+
total+=M[i][j+1]
49+
c++
50+
}
51+
returntotal/c
552
}

‎src/0661.Image-Smoother/Solution_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
14-
expectbool
13+
inputs[][]int
14+
expect[][]int
1515
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
16+
{"TestCase", [][]int{{2,3,4}, {5,6,7}, {8,9,10}, {11,12,13}, {14,15,16}}, [][]int{{4,4,5}, {5,6,6}, {8,9,9}, {11,12,12}, {13,13,14}}},
17+
{"TestCase", [][]int{{1,1,1}, {1,0,1}, {1,1,1}}, [][]int{{0,0,0}, {0,0,0}, {0,0,0}}},
1918
}
2019

2120
//开始测试

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp