Java 0ms 100%faster simple easy solution with O(1) space
\nPlease Upvote if you find this helpful\n\nclass Solution {\n    public int[][] flipAndInvertImage(int[][] image) {\n        for (int i = 0; i < image.length; 
![image](https://assets.leetcode.com/users/images/f42b9943-7177-4657-a40e-c32e5135d651_1648870130.589014.png)\n***Please Upvote if you find this helpful***\n```\nclass Solution {\n    public int[][] flipAndInvertImage(int[][] image) {\n        for (int i = 0; i < image.length; i++){\n            int s = 0;\n            int e = image[i].length-1;\n            while (s<e){\n                int temp = image[i][s];\n                image[i][s] = image[i][e];\n                image[i][e] = temp;\n                s++;\n                e--;\n            }\n        }\n        for(int i = 0; i < image.length; i++){\n            for (int j = 0; j < image[i].length; j++){\n                if(image[i][j] == 0){\n                    image[i][j] = 1;\n                }\n                else if(image[i][j] == 1){\n                    image[i][j] = 0;\n                }\n            }\n        }\n        return image;\n    }\n}\n```\n```\nclass Solution {\n    public int[][] flipAndInvertImage(int[][] image) {\n        for (int i = 0; i < image.length; i++) {\n            int temp = image[i].length;\n            if (temp % 2 == 1) {\n                image[i][temp/2] = image[i][temp/2] == 1 ? 0 : 1;\n            }\n            int start = 0;\n            int end = temp - 1;\n            while (end > start) {\n                flip(image[i], start, end);\n                start++;\n                end--;\n            }\n        }\n        return image;\n    }\n    private void flip(int[] arr, int firstIndex, int lastIndex) {\n        int temp = arr[firstIndex];\n        arr[firstIndex] = arr[lastIndex];\n        arr[lastIndex] = temp;\n        arr[firstIndex] = arr[firstIndex] == 1 ? 0 : 1;\n        arr[lastIndex] = arr[lastIndex] == 1 ? 0 : 1;\n    }\n}\n```\n
['Array', 'Java']