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 e4481a8

Browse files
committed
832
1 parent 759368d commit e4481a8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
class Solution
3+
{
4+
/**
5+
* @param Integer[][] $image
6+
* @return Integer[][]
7+
*/
8+
public function flipAndInvertImage($image)
9+
{
10+
foreach ($image as &$row) {
11+
$row = array_reverse($row);
12+
13+
foreach ($row as &$pixel) {
14+
15+
$pixel = $pixel == 0 ? 1 : 0;
16+
// $pixel = $pixel ^ 1; // bitwise XOR operator
17+
}
18+
}
19+
return $image;
20+
}
21+
}
22+
$solution = new Solution();
23+
24+
$image = [[1, 1, 0], [1, 0, 1], [0, 0, 0]];
25+
26+
$result = $solution->flipAndInvertImage($image);
27+
28+
print_r($result);

0 commit comments

Comments
(0)

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