Skip to content

Commit 3e52a0b

Browse files
committedApr 20, 2025
Add solution #832
1 parent 46122ba commit 3e52a0b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,392 LeetCode solutions in JavaScript
1+
# 1,393 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -645,6 +645,7 @@
645645
829|[Consecutive Numbers Sum](./solutions/0829-consecutive-numbers-sum.js)|Hard|
646646
830|[Positions of Large Groups](./solutions/0830-positions-of-large-groups.js)|Easy|
647647
831|[Masking Personal Information](./solutions/0831-masking-personal-information.js)|Medium|
648+
832|[Flipping an Image](./solutions/0832-flipping-an-image.js)|Easy|
648649
833|[Find And Replace in String](./solutions/0833-find-and-replace-in-string.js)|Medium|
649650
834|[Sum of Distances in Tree](./solutions/0834-sum-of-distances-in-tree.js)|Hard|
650651
835|[Image Overlap](./solutions/0835-image-overlap.js)|Medium|

‎solutions/0832-flipping-an-image.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 832. Flipping an Image
3+
* https://leetcode.com/problems/flipping-an-image/
4+
* Difficulty: Easy
5+
*
6+
* Given an n x n binary matrix image, flip the image horizontally, then invert it, and
7+
* return the resulting image.
8+
*
9+
* To flip an image horizontally means that each row of the image is reversed.
10+
* - For example, flipping [1,1,0] horizontally results in [0,1,1].
11+
*
12+
* To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.
13+
* - For example, inverting [0,1,1] results in [1,0,0].
14+
*/
15+
16+
/**
17+
* @param {number[][]} image
18+
* @return {number[][]}
19+
*/
20+
var flipAndInvertImage = function(image) {
21+
return image.map(row => row.reverse().map(num => 1 ^ num));
22+
};

0 commit comments

Comments
 (0)