File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Bitwise_XOR ;
2
+
3
+ // Problem Statement: Flip and Invert an Image (hard)
4
+ // LeetCode Question: 832. Flipping an Image
5
+
6
+ public class Problem_4_Flip_And_Invert_An_Image {
7
+ public int [][] flipAndInvertImage (int [][] arr ) {
8
+ int C = arr [0 ].length ; // Get the number of columns in the input matrix
9
+ for (int [] row : arr ) { // Iterate through each row in the matrix
10
+ for (int i = 0 ; i < (C + 1 ) / 2 ; ++i ) { // Iterate through the first half of each row
11
+ int tmp = row [i ] ^ 1 ; // Invert the current element and store it in tmp
12
+ row [i ] = row [C - 1 - i ] ^ 1 ; // Invert and swap elements symmetrically from the beginning and end of the row
13
+ row [C - 1 - i ] = tmp ; // Update the end element with the temporary value
14
+ }
15
+ }
16
+ return arr ; // Return the modified matrix
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments