Need help on output generation

  • 0
    public class Solution {
        public void rotate(int[][] matrix) {
            int m = matrix.length;
            matrix = transpose(matrix);
            for(int i=0;i<=m/2;i++){
                matrix = swapColumns(i,m-1-i,matrix);
        public int[][] transpose(int[][] a){
            int m= a.length;
            int[][] b = new int[m][m];
            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    b[i][j] = a[j][i];
             a = b;
            return a;
        public int[][] swapColumns(int i,int j,int[][] a){
            int m = a.length;
            for(int k=0;k<m;k++){
                int temp = a[k][i];
                a[k][i] = a[k][j];
                a[k][j] = temp;
            return a;

    I am able to get correct output when I get standard output in the rotate function. But somehow the output shown here is not changed. Could reference passing be an issue here? When matrix is being passed and modified

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.