Rotate Image [LeetCode]
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?
Solution:
void rotate(vector<vector<int> > &matrix) {
int n = matrix.size();
for(int i = ; i < n / ; i ++) {
for(int j = i; j < n - - i; j ++){
int tmp = matrix[i][j];
matrix[i][j] = matrix[n - - j][i];
matrix[n - - j][i] = matrix[n - - i][n - - j];
matrix[n - - i][n - - j] = matrix[j][n - - i];
matrix[j][n - - i] = tmp;
}
}
}
Rotate Image [LeetCode]的更多相关文章
- 48. Rotate Image - LeetCode
Question 48. Rotate Image Solution 把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转 public void rotate(int[ ...
- Rotate List —— LeetCode
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- Rotate Array leetcode
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- Rotate Image leetcode java
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- Rotate List leetcode java
题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Gi ...
- 189. Rotate Array - LeetCode
Question 189. Rotate Array Solution 题目大意:数组中最后一个元素移到第一个,称动k次 思路:用笨方法,再复制一个数组 Java实现: public void rot ...
- 796. Rotate String - LeetCode
Question 796. Rotate String Solution 题目大意:两个字符串匹配 思路:Brute Force Java实现: public boolean rotateString ...
- Rotate List || LeetCode
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * } ...
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
随机推荐
- Life is hard
Life is hard, always so.If there's anything to give you a hard life with sunshine and warmth, please ...
- 7.$a = 'abcdef'; 请取出$a的值并打印出第一个字母
echo $a[0]; echo $a{0}; echo chr(ord($a));//先输出$a字符串里的第一个字符的ASCII值 再从指定的 ASCII 值返回字符.
- AJAX-----09iframe模拟ajax文件上传效果原理1
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Magento 自定义一个搜索功能
最近工作中有一个需求是需要做一个搜索的功能,但是因为需要定制一些外观,所以就不用传统的方法来继承基类GRID.实现这个需求的核心其实就是下面这个方法. $this->getLayout()-&g ...
- Orchard part8
http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-8 定 ...
- HtmlHelper的扩展
HtmlHelper的扩展: 注意点:扩展方法必须是静态方法,所在的类必须是静态类,所在的命名空间改成System.Web.MVC则能省略页面中必须添加命名空间的约束. //主要就是输出分页的超级链接 ...
- spring多线程与定时任务
本篇主要描述一下spring的多线程的使用与定时任务的使用. 1.spring多线程任务的使用 spring通过任务执行器TaskExecutor来实现多线程与并发编程.通常使用ThreadPoolT ...
- 2016年12月18日 星期日 --出埃及记 Exodus 21:13
2016年12月18日 星期日 --出埃及记 Exodus 21:13 However, if he does not do it intentionally, but God lets it hap ...
- centos7 nginx配置httpsCenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx环境部署(二)
1.yum安装nginx 下载对应当前系统版本的nginx包(package) # wget http://nginx.org/packages/centos/7/noarch/RPMS/ngin ...
- int与string之间的类型转换--示例
package demo; public class IntDemo { public static void main(String[] args) { // String-->int 类型转 ...