본문 바로가기
Problem Solving/LeetCode

[LeetCode] 832. Flipping an Image - Java

by graycode 2026. 10. 23.

• 문제 링크

 

Flipping an Image - LeetCode

Can you solve this real interview question? Flipping an Image - Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. * F

leetcode.com

 

• 풀이 코드

public class Solution {

    public int[][] flipAndInvertImage(int[][] image) {
        int n = image.length;
        for (int[] row : image) {
            int l = 0, r = n - 1;
            while (l <= r) {
                int temp = row[l] ^ 1;
                row[l++] = row[r] ^ 1;
                row[r--] = temp;
            }
        }

        return image;
    }

}

댓글