File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* *
2
+ * AC:
3
+ * Runtime: 8 ms, faster than 80.29% of C++ online submissions for Flipping an Image.
4
+ * Memory Usage: 9.2 MB, less than 7.07% of C++ online submissions for Flipping an Image.
5
+ *
6
+ */
7
+ class Solution {
8
+ public:
9
+ vector<vector<int >> flipAndInvertImage (vector<vector<int >>& A) {
10
+ int row = A.size ();
11
+ int col = A[0 ].size ();
12
+
13
+ for (int i = 0 ; i <= row - 1 ; i++) {
14
+ for (int j = 0 ; j < col / 2 ; j++) {
15
+ int temp = A[i][j];
16
+ A[i][j] = A[i][col - 1 - j];
17
+ A[i][col - 1 - j] = temp;
18
+ }
19
+ }
20
+
21
+ for (int i = 0 ; i <= row - 1 ; i++) {
22
+ for (int j = 0 ; j <= col - 1 ; j++) {
23
+ if (A[i][j] == 0 ) {
24
+ A[i][j] = 1 ;
25
+ } else {
26
+ A[i][j] = 0 ;
27
+ }
28
+ }
29
+ }
30
+
31
+ return A;
32
+ }
33
+ };
You can’t perform that action at this time.
0 commit comments