Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of flipping Image by leetcode

Shulou Source: shulou.com Published: 2022-06-01 13:22:34 09月16日 Update

This article will explain in detail how leetcode solves the problem of flipping images. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.

I. Content of the topic

Given a binary matrix A, we want to flip the image horizontally first, then invert the image and return the result.

Flip horizontally is to flip every line of the picture, that is, reverse order. For example, flipping [1, 1, 0] horizontally results in [0, 1, 1].

Inverting a picture means that all zeros in the picture are replaced by ones, and all ones are replaced by zeros. For example, inverting [0, 1, 1] results in [1, 0, 0].

Example 1:

Input: [[1,1,0],[1,0,1],[0,0,0]]

Output: [[1,0,0],[0,1,0],[1,1,1]]

Explanation: First flip each line: [[0,1,1],[1,0,1],[0,0,0]];

Then invert the picture: [[1,0,0],[0,1,0],[1,1,1]]

Example 2:

Input: [[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]]

Explanation: First flip each line: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]];

Then invert the picture: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]

Tip:

1

Tags: Picture horizontal image one line article result question symmetry position content numerical value more example interpretation input output different good practical binary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi macOS Docker Linux