【算法题】矩阵顺时针旋转90° (js)

力扣链接:https://leetcode.cn/problems/rotate-matrix-lcci/description/

在这里插入图片描述
本人题解:

/**
 * @param {number[][]} matrix
 * @return {void} Do not return anything, modify matrix in-place instead.
 */
var rotate = function (matrix) {
   
    const x = matrix.length || 0;
    const y = x > 0 ? matrix[0]?.length : 0;
    if (x === 0) return [];
    if (y === 1) return matrix;
    for (let i = 0; i < x; i++) {
   
        for (let j = i; j < y; j++) {
   
            const temp = matrix[i][j];
            matrix[i][j] = matrix[j][i];
            matrix[j][i] = temp;
        }
    }
    return matrix.map((item) => item.reverse());
};

相关推荐

  1. css时针旋转90°再3D中绕Y轴旋转180°

    2023-12-28 10:38:08       41 阅读
  2. 记(44)--矩阵旋转

    2023-12-28 10:38:08       24 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-28 10:38:08       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-28 10:38:08       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-28 10:38:08       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-28 10:38:08       20 阅读

热门阅读

  1. LeetCode——2660. 保龄球游戏的获胜者

    2023-12-28 10:38:08       35 阅读
  2. Error: EACCES: permission denied, access

    2023-12-28 10:38:08       39 阅读
  3. 设计模式之状态模式

    2023-12-28 10:38:08       41 阅读
  4. Elasticsearch 常用 REST API 之集群APIs

    2023-12-28 10:38:08       32 阅读
  5. 【前端框架】NPM概述及使用简介

    2023-12-28 10:38:08       36 阅读
  6. 如何解决服务器CA证书过期的问题

    2023-12-28 10:38:08       44 阅读
  7. centos 7.9 安装 qt5.15.11

    2023-12-28 10:38:08       48 阅读
  8. 【后端】拷贝数据字典

    2023-12-28 10:38:08       40 阅读