资源 · 指南或文章
Square Matrix In-Place Rotation
通过连续做两次翻转,在不另外分配矩阵的情况下把 n 乘 n 矩阵顺时针旋转 90 度。
审核日期
打开原站: Square Matrix In-Place Rotation (在新标签页中打开原网站)添加到路线图
把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。
来源内容语言:英语
You are given an n x n 2D matrix (representing an image). Rotate the matrix by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. Rotate the input matrix in-place such that it becomes:
PrepKit 概览
本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。
- 适合人群
- 来源未说明适用级别
- 形式
- 课程
涵盖内容
- 3x3 和 4x4 示例,附旋转前后的矩阵
- 两种都能实现旋转的翻转顺序
- 一个用纸片判断该用哪些翻转的小技巧
- 一张文本示意图,追踪第一行先经对角线翻转、再经水平翻转的过程
使用建议
这是 PrepKit 的学习建议,并非来源的说法。
按其中一种翻转顺序在纸上旋转 4x4 示例,编写代码,并确认输出一致。然后解释你会如何逆时针旋转。
范围与局限
页面上没有复杂度或代码,算法部分有一处文字混乱(“Or we also could Furthermore”)。唯一的参考资料是 LeetCode。
获取方式与形式
GitHub 上的 README,trekhleb/javascript-algorithms(MIT)。英文,免费阅读。
PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88
本概览的依据
- src/algorithms/uncategorized/square-matrix-rotation/README.md
收录此条目的页面
订阅 PrepKit 通讯
可选。使用 PrepKit 并不需要订阅。