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 ...
随机推荐
- jQuery-实现图片的放大镜显示效果
jQuery-实现图片的放大镜显示效果 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/word ...
- HYSBZ 2565 最长双回文串 (回文树)
2565: 最长双回文串 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1377 Solved: 714 [Submit][Status][Dis ...
- CodeForces 17E Palisection(回文树)
E. Palisection time limit per test 2 seconds memory limit per test 128 megabytes input standard inpu ...
- STL中使用reverse_iterator时,如何正确使用erase函数
假设有一个list容器,顺序存储了0-9一个10个整数.现在要使用reverse_iterator迭代器来查找值为8和5的元素,并且将这两个数删除.先来看以下的解决方法: #include <i ...
- Linux(7)- Nginx.conf主配置文件、Nginx虚拟主机/访问日志/限制访问IP/错误页面优化、Nginx反向代理、Nginx负载均衡
一.Nginx.conf主配置文件 Nginx主配置文件conf/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块的形式组织的.一般,每个区块以一对大括号{}来表示开始与结束. 核心模 ...
- mongo 一次插入多条
db.getCollection('organization').insert( [ {"organizationTitle" : "台州广播电台1", &qu ...
- PyNest——part 3: connecting networks with synapses
part 3: connecting networks with synapses parameterising synapse models NEST提供了各种不同的突触模型. 您可以使用命令nes ...
- Go 结构体和map等数据结构转json字符串
Go语言中使用json包中的 Marshal() 函数将数据结构转成json字符串,源代码: func Marshal(v interface{}) ([]byte, error) { e := ne ...
- GIT学习笔记(3):分支管理
GIT学习笔记(3):分支管理 何谓分支 GIT是如何存储数据的 GIT不是存储文件差异或者变化量,而是一系列文件的快照.在Git提交时,会保存一个提交(commit)对象,该对象包含一个指向暂存内容 ...
- springboot的Scheduled定时器不工作
问题情况 使用springboot,使用注解方式启动定时器进行业务调度. 在入口类中加了注解如下: package org.test.xyz; @SpringBootApplication @Enab ...