leetCode 48.Rotate Image (旋转图像) 解题思路和方法
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?
思路:事实上就是旋转数组。没有什么难度。代码例如以下:
public class Solution {
public void rotate(int[][] matrix) {
int[][] a = new int[matrix.length][matrix.length];
//实现深拷贝
for(int i = 0; i < matrix.length; i++){
for(int j = 0; j < matrix.length;j++){
a[i][j] = matrix[i][j];
}
}
//数据旋转
for(int i = 0; i < a[0].length; i++){
int k = 0;
for(int j = a.length-1; j >=0; j--){
matrix[i][k++] = a[j][i];
//System.out.print(a[j][i] + " ");
}
//System.out.println("");
}
}
}
leetCode 48.Rotate Image (旋转图像) 解题思路和方法的更多相关文章
- [LeetCode] 48. Rotate Image 旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- [leetcode]48. Rotate Image旋转图像
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- leetCode 72.Edit Distance (编辑距离) 解题思路和方法
Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert ...
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- [LeetCode] 76. Minimum Window Substring 解题思路
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- [LeetCode] Minimum Size Subarray Sum 解题思路
Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...
- [LeetCode] 45. Jump Game II 解题思路
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] 234. Palindrome Linked List 解题思路
Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time ...
- [LeetCode] Largest Rectangle in Histogram 解题思路
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
随机推荐
- Mavne + Spring整合CXF
http://blog.csdn.net/xiongyu777888/article/details/23787615(没毛病) http://blog.csdn.net/hbsong75/artic ...
- hibernate_validator_04
对象图--个人觉得就是关联验证 ean Validation API不仅能够用来校验单个的实例对象,还能够用来校验完整的对象图.要使用这个功能,只需要在一个有关联关系的字段或者属性上标注 @Valid ...
- 多个显示器, window.open的定位
// Pops a window relative to the current window position function popup(url, winName, xOffset, yOffs ...
- jquery mobile 栅格化
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- jQuery 使用 jQuery UI 部件工厂编写带状态的插件(翻译)
首先,我们要创建一个progress bar,它只允许我们简单的设置进度值.正如我们接下来将要看到的,我们需要通过调用 jQuery.widget 及其两个参数来实现这一操作,这两个参数分别是:将要创 ...
- sublime2开发Python的编码问题
在sublime2文本编辑器直接开发python程序会出现错误 Traceback (most recent call last): File ".\sublime_plugin.py&qu ...
- Lang语言包
\languages\zh_cn\admin\common.php里配置后台所有常量
- 编写可维护的javascript代码---开篇(介绍自动报错的插件)
文章开篇主要推荐了2款检测编程风格的工具: JSLint和JSHint: jsLint是由Douglas Crockford创建的.这是一个通用的javascript代码质量检测工具,最开始JSLin ...
- python模块之json序列化
31.序列化: 1.json实现序列化,json.dumps()和json.loads(). >>> s1 = {'k1':'v1','k2':'v2' ...
- C++学习笔记5——类的继承
简介: 通过继承联系在以前的类构成一种层次关系.通常在层次关系的根部有一个基类,其他类则直接或间接地从基类继承,这些继承得到的类称为类的派生类. 作用: 1.子类拥有父类的所有成员函数和成员变量. 2 ...