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,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
随机推荐
- for循环求交集
for循环方式求交集 #!/usr/bin/env python #coding:utf-8 #取交集 #定义两个序列对象,求alist与blist对象的交集元素 alist = [2,9,3,4,5 ...
- php 正则提取数字
<?php//$patterns = "/^(http|https):\/\/(.)*\.(.)*$/";$patterns = "/\d+/";$str ...
- 一种构造WEB服务器端recv和send接口阻塞现象的方法
send阻塞 socket recv send接口阻塞,会导致服务器端不在响应客户端任何请求,所以一般情况, 会将socket设置为非阻塞状态, 但是有些场景,例如ssl_accept就需要使用阻塞的 ...
- DOM based XSS Prevention Cheat Sheet(DOM Based XSS防御检查单)
本文为翻译版本,原文请查看 https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet 介绍 谈到XSS攻击,有三种公认的 ...
- AngularJS Best Practices: ASP.NET MVC Directory Structure
/Content----- images/ // Images for your app----- css/ // Styles for your app/Scripts----- libs/ // ...
- MVC EF 执行SQL语句
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 闲着没事,看了一篇关于LINQ和SQL对比的文章,网友们 ...
- java学习规划
今天在网上看到一位大学生的java学习线路规划,觉得蛮适合我,就详细阅读了一下,规划路线应该适用于大部分学习java语言的人,贴出来与大家共勉. 在学习的过程中,不能急于去学习更多的知识,因为知识是无 ...
- Ubantu16.4的安装过程以及基本配置
Ubantu16.4的安装过程以及基本配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入高级运维工程师之路:598432640 其实很早以前就听朋友说ubantu这怎么好 ...
- SpringMVC学习系列(3) 之 URL请求到Action的映射规则
在系列(2)中我们展示了一个简单的get请求,并返回了一个简单的helloworld页面.本篇我们来学习如何来配置一个action的url映射规则. 在系列(2)中我们在HelloWorldContr ...
- Dundas控件的X轴字体竖排版
dundas 坐标轴的问题 x轴的值怎么让他竖排显示?我晓得dundas可以旋转显示,但是不是我要的效果 如下 --------------------------------------- 第 ...