public class RotateImage {
public void rotate(int[][] matrix)
{
if(matrix.length == 1 && matrix[0].length == 1)
{
return;
}
int n = matrix.length;
for(int i = 0; i < n-1; i ++)
{
for(int j = i; j < n-1-i; j ++)
{
int temp = matrix[i][j];
matrix[i][j] = matrix[n-1-j][i];
matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
matrix[j][n-1-i] = temp;
}
}
} public static void main(String[] args)
{
RotateImage ri = new RotateImage();
int[][] a = {{1,2,3},{4,5,6},{7,8,9}};
ri.rotate(a);
//ri.rotate(a);
//ri.rotate(a);
//ri.rotate(a);
for (int[] is : a)
{
for (int i : is)
{
System.out.print(i+" ");
}
System.out.println("\n\r");
}
}
}

  

Rotate Image,N*N矩阵顺时针旋转90度的更多相关文章

  1. 将n*n矩阵顺时针旋转90度

    /** * 将n*n矩阵顺时针旋转90度 * @param mat * @param n 矩阵的阶数 * @date 2016-10-7 * @author shaobn */ public stat ...

  2. python 矩阵顺时针旋转90度

    # 4*4矩阵旋转90度 def matrix_transposition(data): for index,row in enumerate(data): for col in range(inde ...

  3. LeetCode——Rotate Image(二维数组顺时针旋转90度)

      问题: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw ...

  4. Python之二维数组N*N顺时针旋转90度

    需求:把一个二维数组顺时针旋转90度,现实数据的替换. 比如把4*4的二维数组顺时针旋转90度 原始数据是一个嵌套列表:[['A', 'B', 'C', 'D'], ['A', 'B', 'C', ' ...

  5. 文字顺时针旋转90度(纵向)&古诗词排版

    1.文字旋转90度 width: 100px; height: 200px; line-height: 100px; text-align: center; writing-mode: vertica ...

  6. leetcode 将一个二维矩阵进行90度旋转

    import numpy as np import math if __name__ == '__main__': def rotate(matrix): n = len(matrix[0]) for ...

  7. LeetCode48, 如何让矩阵原地旋转90度

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode第29篇,我们来看一道简单的矩阵旋转问题. 题意 题目的要求很简单,给定一个二维方形矩阵,要求返回矩阵旋转90度之后的 ...

  8. Rotate Image(二位数组顺时针旋转)

    问题描述: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw ...

  9. 2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/100 ...

随机推荐

  1. [UVa OJ] Longest Common Subsequence

    This is the classic LCS problem. Since it only requires you to print the maximum length, the code ca ...

  2. cocos2d-X学习之主要类介绍:摄像机(CCCamera)

    在cocos2d-x中,每个节点(CCNode)都需要用到,即当节点发生旋转.缩放和位置变化等时,都需要覆盖CCCamera,然后这个节点通过CCCamera重新渲染. 类结构: 其主要函数如下: c ...

  3. JavaWeb中servlet读取配置文件的方式

    我们在JavaWeb中常常要涉及到一些文件的操作,比如读取配置文件,下载图片等等操作.那我们能不能采用我们以前在Java工程中读取文件的方式呢?废话不多说我们来看看下我们以前在Java工程中读取文件是 ...

  4. 巨蟒python全栈开发数据库攻略6:索引2&重要内容汇总

    1.索引的添加和删除 2.正确命中索引举例,explain优化神奇的简单使用 3.联合索引 4.简述慢日志记录 5.用户创建和权限分配 6.mysqldump逻辑备份,浅谈主从复制和读写分离 7.浅谈 ...

  5. k近邻算法python实现 -- 《机器学习实战》

    ''' Created on Nov 06, 2017 kNN: k Nearest Neighbors Input: inX: vector to compare to existing datas ...

  6. decode-encode --其他使用可能有问题

    SELECT id,DECODE(name,'password') FROM test UPDATE test SET `name`=ENCODE(`name`,'password')

  7. YARN - Yet Another Resource Negotiator

    http://www.socc2013.org/home/program http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-ya ...

  8. Tornado实战

    抽屉之Tornado实战(1)--分析与架构 抽屉之Tornado实战(2)--数据库表设计 抽屉之Tornado实战(3)--注册 抽屉之Tornado实战(4)--发帖及上传图片 抽屉之Torna ...

  9. spring整合问题分析之-Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

    1.异常分析 Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into ...

  10. Config Static IP Address manually in Ubuntu

    The process of the configuration of static IP address in Ubuntu is as follows: ``` $ sudo vim /etc/n ...