Java code which beats 100%


  • 0
    C
    class Solution {
        public void rotate(int[][] matrix) {
            for (int i = 0; i < matrix.length / 2; i++) {
                int len = matrix.length - 2 * i - 1;
                                                         
                for (int j = 0; j < len; j++) {
                    int temp = matrix[i][i + j + 1];
                    matrix[i][i + j + 1] = matrix[i + len - 1 - j][i];
                    matrix[i + len - 1 - j][i] = matrix[i + len][i + len - 1 - j];
                    matrix[i + len][i + len - 1 - j] = matrix[i + 1 + j][i + len];
                    matrix[i + 1 + j][i + len] = temp;
                }
            }
        }
    }
    

Log in to reply
 

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