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 ...
随机推荐
- Css四种样式
1. 2 3 4 5 6.
- [个人原创]关于java中对象排序的一些探讨(三)
这篇文章由十八子将原创,转载请注明,并标明博客地址:http://www.cnblogs.com/shibazijiang/ 对对象排序也可以使用Guava中的Ordering类. 构造Orderin ...
- 爬虫爬oj用户头像
import requests import Queue import urllib import urllib2 import re import requests alreadyImg = set ...
- IOS 真机调试以及发布应用 1
参考网站:http://my.oschina.net/u/1245365/blog/196263 Certificates, Identifiers &Profiles 简介 Certif ...
- SqlParameter的用法和好处
关于Sql注入的基本概念,相信不需要多说,大家都清楚,经典的注入语句是' or 1=1--单引号而截断字符串,"or 1=1"的永真式的出现使得表的一些信息被暴露出来,如果sql语 ...
- Qt信号槽连接在有默认形参下的情况思考
写下这个给自己备忘,比如函数 ) 你在调用端如论是test(3)或者test(),都可以正确调用到这个函数. 但是,如果放到Qt中的信号槽的话,这个还是值得讲一讲的,不然的话,可能会引起相应的误会. ...
- javascript获得给定日期的前一天的日期
/** * 获得当前日期的前一天 */ function getYestoday(date){ var yesterday_milliseconds=date.getTime()-1000*60*60 ...
- ext等待提示
1.Store加载信息等待 ExtJs的Store在加载时候一般是延迟加载的,这时候Grid就会先出现一片空白,等加载完成后才出现数据:因此,我们需要给它添加一个提示信息! 但是Store却没有wai ...
- JavaBean与EJB的区别与应用
JavaBean 是一种组件,它在内部有接口或有与其相关的属性,以便不同人在不同时间开发的 bean 可以询问和集成. EJB 是部署在服务器上的可执行组件或商业对象.有一个协议允许对其进行远程访问或 ...
- Swift互用性: 使用Objective-C特性编写Swift类(Swift 2.0版)-b
本节包括内容: 继承Objective-C的类(Inheriting from Objective-C Classes) 采用协议(Adopting Protocols) 编写构造器和析构器(Writ ...