反转图片(力扣题库)

public static void main(String[] args) {
            flipAndInvertImage(new int[][]{{1,1,0},{1,0,1},{0,0,0}});
        
    }

    public static int[][] flipAndInvertImage(int[][] A) {
        for (int i = 0; i < A.length; i++) {//翻转
            for (int j = 0; j <(int)(A[i].length/2); j++) {
                A[i][j]=A[i][j]+A[i][A[i].length-j-1];
                A[i][A[i].length-j-1]=A[i][j]-A[i][A[i].length-j-1];
                A[i][j]=A[i][j]-A[i][A[i].length-j-1];
            }
        }
        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < A[i].length; j++) {//反转
                if (A[i][j]==1){
                    A[i][j]=0;
                }else{
                    A[i][j]=1;
                }
            }
        }
        return A;
    }

你可能感兴趣的:(java算法)