48. 旋转图像 leetcode

发布时间:2024年01月08日
class Solution {
    public void rotate(int[][] matrix) {
        int matrix_len = matrix.length;
        int m_j = matrix_len;

        int m_i = matrix_len / 2;
        for (int i = 0; i < m_i; i++) {
            int max_i = matrix_len - 1 - i;
            int mm_j = m_j - 1;
            for (int j = 0; j < mm_j; j++) {
                int s_m_i = j + i;

                int max_i_j = max_i - j;

                int matrix1 = matrix[i][s_m_i];
                int matrix2 = matrix[i + j][max_i];
                int matrix3 = matrix[max_i][max_i - j];
                int matrix4 = matrix[max_i - j][i];

                matrix[i][s_m_i] = matrix4;
                matrix[i + j][max_i] = matrix1;
                matrix[max_i][max_i_j] = matrix2;
                matrix[max_i_j][i] = matrix3;
            }
            m_j = m_j - 2;
        }
    }
}
文章来源:https://blog.csdn.net/yasuowjh/article/details/135434357
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。