Rotate Matrix
来源:互联网 发布:钮承泽军中乐园知乎 编辑:程序博客网 时间:2024/06/05 00:08
public class RotateMatrix {public static int[][] rotate(int[][] matrix, int flag){int m = matrix.length, n = matrix[0].length;int[][] trans = new int[n][m];//transpose matrixfor (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {trans[j][i] = matrix[i][j];}}if (flag == 1) { // rotate clockwisefor (int i = 0; i < n; i++) {for (int j = 0; j < m / 2; j++) {int tmp = trans[i][j];trans[i][j] = trans[i][m - 1 - j];trans[i][m - 1 - j] = tmp;}}}else { // rotate anti-clockwisefor (int j = 0; j < m; j++) {for (int i = 0; i < n / 2; i++) { int tmp = trans[i][j]; trans[i][j] = trans[n - 1 - i][j]; trans[n - 1 - i][j] = tmp; } }}return trans;}}
阅读全文
0 0
- rotate matrix
- matrix rotate
- Rotate Matrix
- Rotate Image (bi-matrix)
- [Leetcode] Rotate Matrix
- rotate matrix m*n
- 1.8 Rotate Matrix
- LeetCode - 67. Rotate Matrix
- Spiral Matrix & Spiral Matrix II & Rotate Image
- [LeetCode]Spiral Matrix I & II & Rotate Matrix
- rotate matrix from 2 vectors
- Rotate using Flex BitmapData and Matrix
- 【7】Rotate matrix by 90 degrees
- Cracking coding iterview(1.6)Rotate NXN Matrix
- 旋转矩阵(Rotate Matrix)的性质分析
- CC150 1.7 ROTATE MATRIX 旋转矩阵
- 旋转矩阵(Rotate Matrix)的性质分析
- 旋转矩阵(Rotate Matrix)的性质分析
- ES6这些就够了
- es6的十大特性
- 使用Vue-Router 2实现路由功能
- Vue2.0 新手完全填坑攻略—从环境搭建到发布——DT
- axios在vue中的简单配置与使用
- Rotate Matrix
- 【BZOJ4094】 【Usaco2013 Dec】Optimal Milking(权限题)
- 以非root身份安装Python的Module或者Package以及pip安装指定路径
- 【BZOJ4094】【Usaco2013 Dec】Optimal Milking(线段树)
- Java 基础(5)—— 普通代码块、构造代码块、静态代码块
- tensorflow 安装目录在哪里?
- Windows核心编程--线程
- 调试时不用在cmd中输入命令参数,直接在属性页中操作
- java.io.Serializable 序列化