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. Linux shell 脚本中, $@ 和$# 分别是什么意思?

    转自:https://zhidao.baidu.com/question/412833470.html $@:表示所有脚本参数的内容 $#:表示返回所有脚本参数的个数. 示例:编写如下shell脚本, ...

  2. 160801、BlockingQueue处理多线程

    前面介绍过spring的taskExecutor,今天介绍一个jdk里处理多线程的方法 一.spring的配置文件(注入bean) <bean id="cmsClickButtonMn ...

  3. debian各种包

    1 zlib compression library sudo apt-get install zlib1g-dev 2 c-ares库 libc-ares-dev - asynchronous na ...

  4. 关于this,作用域,属性,原型链的一个小练习

    function p () { this.name = 'x'; var name = 'y'; this.getName = function () { return name; } } // 求值 ...

  5. django之contenttype

    平时开发过程中,我们会经常遇到这么一个类似的场景,比如 不同的课程,有不同的价格策略 不同的课程可使用不同的优惠券(满减券,通用券,专用券) 不同的评论区,支持的评论 就拿  不同的课程,有不同的价格 ...

  6. Java 集合框架之 JDK 1.5 新特性

    forEach 循环 多用于元素迭代. 适用范围: - 数组 - 实现 Iterable 接口的集合类 格式: for(类型 变量 : Collection 集合 | 数组) { } 传统 for 和 ...

  7. caffe web demo运行+源码分析

    caffe web demo学习 1.运行 安装好caffe后,进入/opt/caffe/examples/web_demo/的caffe web demo项目目录,查看一下app.py文件,这是一个 ...

  8. delphi 模拟POST提交数据

    unit GetHttpInfo; interface uses Classes, WinINet, Sysutils, windows, IDURI, IdSSLOpenSSL , IdBaseCo ...

  9. Andrew Ng机器学习总结(自用)

    监督学习: 线性回归,逻辑回归,神经网络,支持向量机. 非监督学习: K-means,PCA,异常检测 应用: 推荐系统,大规模机器学习 机器学习系统优化: 偏差/方差,正则化,下一步要进行的工作:评 ...

  10. TimeQuest学习总结

    1. 基本时钟约束:creat_clock 2. 生成时钟约束:creat_generated_clock 3. I/O输入输出约束:(1)纯组合逻辑:set_max_delay & set_ ...