Flip and Invert Image

Given a binary matrix, flip each row horizontally and then invert it (0→1, 1→0). Return the resulting matrix (LeetCode 832).

Input Format

2D list of 0/1 ints.

Output Format

2D list after flip+invert.

Constraints

  • m,n ≤ 20; values 0/1.

Examples

Example 1:

Input:

image = [[1,1,0],[1,0,1],[0,0,0]]

Output:

[[1,0,0],[0,1,0],[1,1,1]]

Example 2:

Input:

image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]

Output:

[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]

Example 3:

Input:

image = [[1]]

Output:

[[0]]
Loading...
Flip and Invert Image - Matrix DSA Problem