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?

class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
int temp;
for(int i = ; i < matrix.size()/; i++)
{
for(int j = i; j < matrix[].size()-i-; j++)
{
temp = matrix[i][j];
matrix[i][j] = matrix[matrix[].size()--j][i];
matrix[matrix[].size()--j][i] = matrix[matrix.size()--i][matrix.size()--j];
matrix[matrix.size()--i][matrix.size()--j] = matrix[j][matrix.size()--i];
matrix[j][matrix.size()--i] = temp;
}
}
}
};

48. Rotate Image (Array)的更多相关文章

  1. [array] leetcode - 48. Rotate Image - Medium

    leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...

  2. [Leetcode][Python]48: Rotate Image

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 48: Rotate Imagehttps://leetcode.com/pr ...

  3. 刷题48. Rotate Image

    一.题目说明 题目是48. Rotate Image,简而言之就是矩阵顺时针旋转90度.不允许使用额外的矩阵. 经过观察(写一个矩阵,多看几遍就知道了),旋转90度后: 第1行变为len-1列(最后一 ...

  4. 48. Rotate Image - LeetCode

    Question 48. Rotate Image Solution 把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转 public void rotate(int[ ...

  5. LeetCode 48. Rotate Image(旋转图像)

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  6. 1. 数组小挪移CyclicRotation Rotate an array to the right by a given number of steps.

    数组小挪移: package com.code; import java.util.Arrays; public class Test02_2 { public int[] solution(int[ ...

  7. [LeetCode] 48. Rotate Image 旋转图像

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  8. [leetcode 48] rotate image

    1 题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwi ...

  9. 48. Rotate Image

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

随机推荐

  1. 树的直径证明+HDU2196

    首先把无向图变成一棵树,直径肯定由叶子组成. 有以下两种情况: 第一种:经过根节点,则找两个最远的叶子肯定是直径,也就是B+D. 第二种:不经过根节点,则目标的两个叶子肯定有一个不为根的公共祖先,如红 ...

  2. 【LGR-051】洛谷9月月赛

    [LGR-051]洛谷9月月赛 luogu 签到题 description 给出\(K\)和质数\(m\),求最小的\(N\)使得\(111....1\)(\(N\)个\(1\))\(\equiv k ...

  3. soql取第一件数据

    User u = [select ID,Name from User Limit 1];

  4. 报表生成poi----java操作java对象生成execl表单

    1.Apache POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程式对Microsoft Office格式档案读和写的功能. .NET的开发人员则 ...

  5. swagger api 转graphql npm 包试用

    graphql 比较方便的进行api 的查询,操作,swagger 是一个方便的open api 描述标准,当前我们有比较多的 restapi 但是转换为graphql 是有成本的,还好swagger ...

  6. time函数及其用法

    Linux下三种时间 st_atime:文件中的数据最后被访问的时间           Time when file data was last accessed. Changed by  the  ...

  7. 【转】linux sed命令详解

    原文网址:http://www.iteye.com/topic/587673 1. Sed简介sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”( ...

  8. java 题

    [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析:   兔子的规律为数列1 ...

  9. SQL注入与安全防护---以PHP为例

    一.什么是sql注入: 简单来说,当我们从前端的用户表单数据往后台数据库传输时,可能用户表单数据中的某些数据,会跟我们的后台发生“有机”反应,从而导致发生一些数据库的异常操作. 举个例子吧,以简单的用 ...

  10. 配置 host only 后 nat不能上网了

    如果只有nat 网关为nat 中设置的网关  eth0 启动第二块网卡host_only 网关就变成了 host_only中的网关  eth1 解决放法 route -n 看启用的是哪个网关 [roo ...