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.


	For example, flipping [1,1,0] horizontally results in [0,1,1].


To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.


	For example, inverting [0,1,1] results in [1,0,0].


&nbsp;
Example 1:

Input: image = [[1,1,0],[1,0,1],[0,0,0]]
Output: [[1,0,0],[0,1,0],[1,1,1]]
Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
Then, invert the image: [[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]]
Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].
Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]


&nbsp;
Constraints:


	n == image.length
	n == image[i].length
	1 &lt;= n &lt;= 20
	images[i][j] is either 0 or 1.


class Solution:
    def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]:
        return [[(1 - i) for i in row[::-1]] for row in image]
class Solution {
    public int[][] flipAndInvertImage(int[][] image) {
        for (int i = 0; i < image.length; ++i) {
            flip(image[i]);
        }
        for (int i = 0; i < image.length; ++i) {
            for (int j = 0; j < image[i].length; ++j) {
                image[i][j] = image[i][j] == 1 ? 0:1;
            }
        }
        return image;
    }
    public static void flip(int[] row) {
        int i = 0;
        int j = row.length - 1;
        while (i < j) {
            int temp = row[i];
            row[i] = row[j];
            row[j] = temp;
            ++i;
            --j;
        }
    }
}
class Solution {
public:
    vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image) {
        int n = image.size();
        vector<int >ans;
        for(int i=0;i<image.size();i++){
            ans=image[i];
            reverse(ans.begin(),ans.end());
            image[i]=ans;
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(image[i][j] == 0){
                    image[i][j] = 1;
                }
                else{
                    image[i][j] = 0;
                }
            }
        }
        return image;
    }
};
var flipAndInvertImage = function(image) {
    const resversedArr = []
    for(let i=0; i<image.length; i++){
         resversedArr.push(resverseArr(image[i]));
    }
  return resversedArr;
};

function resverseArr(arr){
    const lastIndex = arr.length -1, reversedArr = [];
    for(i=0; i<=lastIndex; i++){
        if(arr[i] !== arr[lastIndex-i]){
            reversedArr[i] = arr[lastIndex-i] === 0 ? 1 : 0;
            reversedArr[lastIndex-i] = arr[i] === 0 ? 1 : 0;
        }else{
           reversedArr[i] = arr[i] === 0 ? 1 : 0;
        }
    }
    return reversedArr;
}```

/*
*/
Flipping an Image