You are given an `n x n` binary matrix `image`. Flip it horizontally, which reverses every row, and then invert it, which turns every `0` into `1` and every `1` into `0`. Return the resulting image.
For example, flipping `[1,1,0]` gives `[0,1,1]`, and inverting that gives `[1,0,0]`.
You are given an n x n binary matrix image. Flip it horizontally, which reverses every row, and then invert it, which turns every 0 into 1 and every 1 into 0. Return the resulting image.
For example, flipping [1,1,0] gives [0,1,1], and inverting that gives [1,0,0].
Example 1:
Input: {"image":[[1,1,0],[1,0,1],[0,0,0]]}
Output: [[1,0,0],[0,1,0],[1,1,1]]
Constraints:
n==image.length
n==image[i].length
1≤n≤20
image[i][j] is 0 or 1
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"image":[[1,1,0],[1,0,1],[0,0,0]]}
Flip then invert can be done in one pass: walk two pointers in from both ends of each row, swap the pair and invert both with ^ 1.
image (white = 1, black = 0), dashed line = mirror axis