My java solution


  • 0
    S
    public class Solution {
        public void rotate(int[][] matrix) {
            int length = matrix.length;
            int i = 0;
            while(i < (length + 1) / 2){
                for(int j = i; j < length - 1 - i; j ++){
                    int count = 0;
                    int x = i;
                    int y = j;
                    int temp = matrix[x][y];
                    while(count < 3){
                        matrix[x][y] = matrix[length - 1 - y][x];
                        int k = x;
                        x = length - 1 - y;
                        y = k;
                        count ++ ;
                    }
                    matrix[x][y] = temp;
                }
                i ++ ;
            }
        }
    }

Log in to reply
 

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