1 Star 0 Fork 0

表情扭曲 / leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc48.java 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
liu13 提交于 2018-12-27 10:14 . 20181226
package code;
/*
* 48. Rotate Image
* 题意:将数组顺时针翻转90度
* 难度:Medium
* 分类:Array
* 思路:两种思路:先对角,再以竖轴对称;先以横轴对称,再对角.思路很新奇,记一下.
*/
public class lc48 {
public static void main(String[] args) {
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printArr(matrix);
rotate(matrix);
System.out.println();
printArr(matrix);
}
public static void rotate(int[][] matrix) {
for (int i = 0; i <matrix.length ; i++) {
for (int j = 0; j < i; j++) {
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j <matrix[0].length/2; j++) {
int temp = matrix[i][j];
matrix[i][j] = matrix[i][matrix[0].length-1-j];
matrix[i][matrix[0].length-1-j] = temp;
}
}
}
public static void printArr(int[][] matrix){
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
System.out.print(matrix[i][j]);
}
System.out.println();
}
}
}
1
https://gitee.com/abfantasy/leetcode.git
git@gitee.com:abfantasy/leetcode.git
abfantasy
leetcode
leetcode
master

搜索帮助