-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
36 lines (31 loc) · 1.02 KB
/
Solution.cs
File metadata and controls
36 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Text;
namespace LeetCode.Problem832{
//832. Flipping an Image
//https://leetcode.com/problems/flipping-an-image/
/*
Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image.
To flip an image horizontally means that each row of the image is reversed.
For example, flipping [1,1,0] horizontally results in [0,1,1].
To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.
For example, inverting [0,1,1] results in [1,0,0].
*/
public class Solution {
public int[][] FlipAndInvertImage(int[][] image) {
for (int i = 0; i < image.Length; i++)
{
var value = image[i];
int left = 0;
int right = value.Length - 1;
while (right >= left)
{
var tempVal = value[right];
value[right] = 1 - value[left];
value[left] = 1 - tempVal;
right--;
left++;
}
}
return image;
}
}
}