leetcode 48. Rotate Image
来源:互联网 发布:数据清洗的方法不包括 编辑:程序博客网 时间:2024/05/21 07:11
//You are given an n x n 2D matrix representing an image.////Rotate the image by 90 degrees (clockwise).////Follow up://Could you do this in-place?public class Solution {public static void rotate(int[][] matrix) { int row;//标记当前圈数下的数组表示下的最小范围 int col;//正数增加 int length = matrix.length; int edge = length-1;//标记当前圈数下的数组表示下的最大范围 int nEdge;//从最大值的倒数 for(row = 0;row<edge;row++){//向内一圈 nEdge = edge; for(col = row;col<edge;col++,nEdge--){//col = row 保证了按照从外到内一圈一圈的进行遍历;在本圈内进行交换旋转 int val=matrix[row][col]; matrix[row][col] = matrix[nEdge][row]; matrix[nEdge][row] = matrix[edge][nEdge]; matrix[edge][nEdge] = matrix[col][edge]; matrix[col][edge] = val; } edge--;//向内一圈后,最大值也要减1 } }public static void main(String[] args) {int[][] input = {{1,2,3},{4,5,6},{7,8,9}};rotate(input);for(int i = 0;i<input.length;i++){for(int j= 0;j<input.length;j++){System.out.print(input[i][j]);}System.out.println();}} }
0 0
- [LeetCode]48.Rotate Image
- LeetCode 48. Rotate Image
- LeetCode 48.Rotate Image
- LeetCode --- 48. Rotate Image
- [Leetcode] 48. Rotate Image
- [leetcode] 48. Rotate Image
- Leetcode 48. Rotate Image
- 48. Rotate Image LeetCode
- [LeetCode]48. Rotate Image
- leetcode 48. Rotate Image
- Leetcode 48. Rotate Image
- LeetCode 48. Rotate Image
- LeetCode *** 48. Rotate Image
- [LeetCode]48. Rotate Image
- LeetCode 48. Rotate Image
- LeetCode-48.Rotate Image
- [LeetCode] 48. Rotate Image
- LeetCode 48. Rotate Image
- 通过文件的方式对硬盘扇区进行直接读写操作
- NYOJ 76超级台阶问题
- C++之离港篇学习笔记之新特性
- 网易云捕1.5版本已经上线,重磅功能来袭
- Java事务--spring+atomikos+tomcat实现分布式事务
- leetcode 48. Rotate Image
- Pyhton 单行、多行注释符号使用方法及规范
- nagios系列(四)之nagios主动方式监控tcp常用的80/3306等端口监控web/syncd/mysql及url服务
- Unity5学习心得-Input<未完待续>
- Python 的 GUI 开发
- java学习笔记2——异常
- sql经典面试题、练习题
- C++虚函数的工程应用2
- Android技术——注入技术