Array 10 - rotate image

Question URL: https://leetcode.cn/leetbook/read/top-interview-questions-easy/xnhhkv/

public class Solution {
    public void Rotate(int[][] matrix) {
        int len = matrix.GetLength(0)-1;
        for(int i=0;i< matrix.Length; i++)
        {
            for(int j=0;j< matrix[0].Length; j++)
            {
                if ((i + j) < len)
                {
                    int k = matrix[i][j];
                    matrix[i][j] = matrix[len-j][len-i];
                    matrix[len-j][len-i] = k;
                }
            }
        }
        for(int i = 0; i < matrix.Length/2; i++)
        {
            for(int j = 0; j < matrix[0].Length; j++)
            {
                int k = matrix[i][j];
                matrix[i][j] = matrix[len-i][j];
                matrix[len-i][j] = k;
            }
        }
    }
}

 

Guess you like

Origin blog.csdn.net/oyqho/article/details/130026465