Leetcode 832. Flip image

Answer key
They’re very clear, so do what they say, flip it horizontally first, and then flip it backwards.
Horizontal reverse can use its own reverse, reverse directly and 1 XOR can be.
code

class Solution {
public:
    vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
        int n = A.size();
        for(int i = 0; i < n; i++){
            reverse(A[i].begin(),A[i].end());
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < A[0].size(); j++){
                A[i][j] = A[i][j]^1;
            }
        }
        return A;
    }
};

Read More: