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 f5f89df

Browse files
committed
add 832
1 parent fc2bbac commit f5f89df

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# 0832.flipping-an-image
3+
4+
```text
5+
6+
给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果。
7+
8+
水平翻转图片就是将图片的每一行都进行翻转,即逆序。例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]。
9+
10+
反转图片的意思是图片中的 0 全部被 1 替换, 1 全部被 0 替换。例如,反转 [0, 1, 1] 的结果是 [1, 0, 0]。
11+
12+
13+
14+
示例 1:
15+
16+
输入:[[1,1,0],[1,0,1],[0,0,0]]
17+
输出:[[1,0,0],[0,1,0],[1,1,1]]
18+
解释:首先翻转每一行: [[0,1,1],[1,0,1],[0,0,0]];
19+
然后反转图片: [[1,0,0],[0,1,0],[1,1,1]]
20+
示例 2:
21+
22+
输入:[[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
23+
输出:[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
24+
解释:首先翻转每一行: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]];
25+
然后反转图片: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
26+
27+
28+
提示:
29+
30+
1 <= A.length = A[0].length <= 20
31+
0 <= A[i][j] <= 1
32+
33+
来源:力扣(LeetCode)
34+
链接:https://leetcode-cn.com/problems/flipping-an-image
35+
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
36+
```

‎problems/0832.flipping-an-image/run.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package image
2+
3+
import "fmt"
4+
5+
func Run() {
6+
A := [][]int{
7+
[]int{1, 1, 0},
8+
[]int{1, 0, 1},
9+
[]int{0, 0, 0},
10+
}
11+
r := flipAndInvertImage(A)
12+
fmt.Println(r)
13+
}
14+
15+
func flipAndInvertImage(A [][]int) [][]int {
16+
for _, a := range A {
17+
for i := 0; i < len(a)/2; i++ {
18+
a[i], a[len(a)-i-1] = a[len(a)-i-1], a[i]
19+
}
20+
for i := 0; i < len(a); i++ {
21+
a[i] = a[i] ^ 1
22+
}
23+
}
24+
return A
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
package image
3+
4+
import "testing"
5+
6+
func TestRun(t *testing.T) {
7+
Run()
8+
}

0 commit comments

Comments
(0)

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