Java for LeetCode 048 Rotate Image
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?
解题思路:
找规律即可,JAVA实现如下:
static public void rotate(int[][] matrix) {
int[][] matrixArray=new int[matrix.length][matrix[0].length];
for(int i=0;i<matrix.length;i++)
System.arraycopy(matrix[i], 0, matrixArray[i], 0, matrix[i].length);
for(int i=0;i<matrix.length;i++)
for(int j=0;j<matrix.length;j++)
matrix[i][j]=matrixArray[matrix.length-j-1][i];
}
Java for LeetCode 048 Rotate Image的更多相关文章
- [Leetcode][048] Rotate Image 略详细 (Java)
题目在这里 https://leetcode.com/problems/rotate-image/ [个人分析] 这个题目,我觉得就是考察基本功.考察细心的,算法方面没有太多东西,但是对于坐标的使用有 ...
- Java for LeetCode 189 Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- Java for LeetCode 061 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- LeetCode 048 Rotate Image
题目要求:Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 deg ...
- [LeetCode] 61. Rotate List 旋转链表
Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...
- Java for LeetCode 216 Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- Java for LeetCode 214 Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- Java for LeetCode 212 Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- Java for LeetCode 211 Add and Search Word - Data structure design
Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...
随机推荐
- 【CodeForces 618C】Constellation
题 Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars n ...
- str内部方法
代码 #str内部功能 name=' aK am\til.L iu' age=18 num=-11 ab='#' ac=('1','2','3','4','5','6','7') print(dir( ...
- BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...
- 让Jayrock插上翅膀(加入输入输出参数注释,测试页面有注释,下拉框可以搜索)
继上一篇文章介绍了Jayrock组件开发接口的具体步骤和优缺点之后,今天给大家带来的就是,如何修复这些缺点. 首先来回顾一下修复的缺点有哪些: 1.每个接口的只能写大概的注释,不能分开来写,如接口的主 ...
- 02 C语言指针
今天发帖记录自己学习C语言精髓的心理历程,人生就像是一次旅途,沿途总是能看到最美的风景,让我们的思想相逢在C语言中. 一 初识指针,指针的定义 指针是C语言中的一种类型,类似于整形,字符型等.既然C指 ...
- Spring学习8-Spring事务管理(AOP/声明式式事务管理)
一.基础知识普及 声明式事务的事务属性: 一:传播行为 二:隔离级别 三:只读提示 四:事务超时间隔 五:异常:指定除去RuntimeException其他回滚异常. 传播行为: 所谓事务的传播行为 ...
- Oracle 11g ORA-00845: MEMORY_TARGET not supported on this system
启动Oracle 11gR2后报错:ORA-00845 rac1:/home/oracle> sqlplus / as sysdba; SQL*Plus: Release 11.2.0.3.0 ...
- yum被锁Another app is currently holding the yum lock; waiting for it to exit...
可能是系统自动升级正在运行,yum在锁定状态中. 可以通过强制关掉yum进程: #rm -f /var/run/yum.pid 然后就可以使用yum了.
- 序列化LinkedHashMap,有序输出Json字符串
LinkedHashMap本身是有序的,使用JDK自带的序列化代码或者fastJson代码序列化后,字符串并非按照插入顺序输出 Map<String,String> linkedMap=n ...
- NodeJs教程(介绍总结!)终于在网上找到一个靠谱点的了T_T
本人吐槽!本人是学渣,然后网上关于nodeJS的大多都是坑,简直让人要奔溃了.若非最近总是被要求要nodeJS,坚决不会去碰的...天生对cmd命令觉得无比的高大上,尽管一直在用git版本控制器!然后 ...