Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of flipping Image by leetcode

2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report