Rotate Image,N*N矩阵顺时针旋转90度
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度的更多相关文章
- 将n*n矩阵顺时针旋转90度
/** * 将n*n矩阵顺时针旋转90度 * @param mat * @param n 矩阵的阶数 * @date 2016-10-7 * @author shaobn */ public stat ...
- python 矩阵顺时针旋转90度
# 4*4矩阵旋转90度 def matrix_transposition(data): for index,row in enumerate(data): for col in range(inde ...
- LeetCode——Rotate Image(二维数组顺时针旋转90度)
问题: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw ...
- Python之二维数组N*N顺时针旋转90度
需求:把一个二维数组顺时针旋转90度,现实数据的替换. 比如把4*4的二维数组顺时针旋转90度 原始数据是一个嵌套列表:[['A', 'B', 'C', 'D'], ['A', 'B', 'C', ' ...
- 文字顺时针旋转90度(纵向)&古诗词排版
1.文字旋转90度 width: 100px; height: 200px; line-height: 100px; text-align: center; writing-mode: vertica ...
- leetcode 将一个二维矩阵进行90度旋转
import numpy as np import math if __name__ == '__main__': def rotate(matrix): n = len(matrix[0]) for ...
- LeetCode48, 如何让矩阵原地旋转90度
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode第29篇,我们来看一道简单的矩阵旋转问题. 题意 题目的要求很简单,给定一个二维方形矩阵,要求返回矩阵旋转90度之后的 ...
- Rotate Image(二位数组顺时针旋转)
问题描述: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw ...
- 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 ...
随机推荐
- iOS Xcode之SVN(remove git)
项目用SVN比较多,所以大家都把精力放在如何在XCODE上使用SVN. 配置SVN当然是很简单,但提交都默认出现git的提交窗,否则要到repositories界面去提交. 目前没有找到什 ...
- dubbo zookeeper报错failed to connect to server , error message is:No route to host
failed to connect to server , error message is:No route to host 转自:http://blog.csdn.net/miaohongyu1/ ...
- 160725、Java Map按键排序和按值排序
按键排序(sort by key) jdk内置的Java.util包下的TreeMap<K,V>既可满足此类需求,原理很简单,其重载的构造器之一 有一个参数,该参数接受一个比较器,比较器定 ...
- python2 一些错误处理
python2各种问题 pip安装django出错:python2 -m pip install django 编码问题:Unicode Decode Error ascii codec can't ...
- vc判断当前用户是否具有administrator 权限代码
BOOL IsAdmin() { HANDLE hAccessToken; BYTE * InfoBuffer = ]; PTOKEN_GROUPS ptgGroups; DWORD dwInfoBu ...
- [译转]深入理解LayoutInflater.inflate()
原文链接:https://www.bignerdranch.com/blog/understanding-androids-layoutinflater-inflate/ 译文连接:http://bl ...
- Windows 7 下 Node.js 连接 Oracle
原创作者: sailtseng 1. 安装 Oracle 11g express 详见: <Windows 7 x64 安装 Oracle 11g Express> 2. 安装 Micr ...
- Hbase 学习笔记1----shell
Hbase 是一个分布式的.面向列的开源数据库,其实现是建立在google 的bigTable 理论之上,并基于hadoop HDFS文件系统. Hbase不同于一般的关系型数据库(RDBMS ...
- 运用SQLAlchemy
result = engine.execute(s) for row in result: Info["UserId"]=row[0] Info["UserTitle&q ...
- .net:easyui-datagrid清空表中原有数据
$("#StudentTable").datagrid("loadData", { total: 0, rows: [] });