题目要求: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?

代码如下:

class Solution {
public:
void rotate(vector<vector<int> > &matrix) { const int n = matrix.size(); for(int i = 0; i < n; i++) //沿着副对角线反转
for(int j = 0; j < n - i; j++)
swap(matrix[i][j], matrix[n - 1 - j][n - 1 - i]); for(int i = 0; i < n / 2; i++)//沿着水平中线反转
for(int j = 0; j < n; j++)
swap(matrix[i][j], matrix[n - 1 - i][j]); }
};

LeetCode 048 Rotate Image的更多相关文章

  1. [Leetcode][048] Rotate Image 略详细 (Java)

    题目在这里 https://leetcode.com/problems/rotate-image/ [个人分析] 这个题目,我觉得就是考察基本功.考察细心的,算法方面没有太多东西,但是对于坐标的使用有 ...

  2. Java for LeetCode 048 Rotate Image

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

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

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

  4. [LeetCode] 61. Rotate List 旋转链表

    Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...

  5. 【LeetCode】048. Rotate Image

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

  6. LeetCode 189. Rotate Array (旋转数组)

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  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(2D图像旋转问题)

    题目链接: https://leetcode.com/problems/rotate-image/?tab=Description   Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...

  9. 【LeetCode】 Rotate List 循环链表

    题目:rotate list 解法1: <span style="font-size:18px;">/**LeetCode Rotate List:Given a li ...

随机推荐

  1. openshift 平台上部署 gitlab代码仓库服务

    背景: 本文档将以在openshift 平台上部署 gitlab 服务来验证集群各个服务组件的可用性以及熟悉openshift的使用方法.服务部署方式可以多种多样,灵活部署.本篇以常见的镜像部署方式来 ...

  2. 调度《Taint(污点) 和 Toleration(容忍)》

    节点亲和性(详见这里),是 pod 的一种属性(偏好或硬性要求),它使 pod 被吸引到一类特定的节点.Taint 则相反,它使 节点 能够 排斥 一类特定的 pod. Taint 和 tolerat ...

  3. Python实现微信支付(三种方式)

    Python实现微信支付(三种方式) 关注公众号"轻松学编程"了解更多. 如果需要python SDk源码,可以加我微信[1257309054] 在文末有二维码. 一.准备环境 1 ...

  4. Redis中的一致性哈希问题

    在说redis中的哈希(准确来说是一致性哈希)问题之前,先来看一个问题:为什么在分布式集群中一致性哈希会得到大量应用? 在一个分布式系统中,要将数据存储到具体某个节点,或者将来自客户端的请求分配到某个 ...

  5. Javasript中this指向问题和改变this指向的方法

    在学习javascript中我们往往会被this的指向问题弄的头昏转向,今天我们就来学习一下this的指向问题,和改变this指向的方法. 一.this的指向问题 在学习this的指向问题之前我们需要 ...

  6. PHP博客

    创建数据库 用户表 blog_user userid int 用户id username varchar(50) 用户名 password varchar(30) 密码 type tinyint(2) ...

  7. C++实现学校运动会管理系统

    本文实例为大家分享了C++实现学校运动会管理系统的具体代码,供大家参考,具体内容如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  8. -bash: bash_profile: command not found问题

    这个问题一般就是.bash_profile 文件内容错误,里面内容没加注释之内的,vi .bash_profile打开文件检查一下,然后:wq!保存退出 我的错误就是红圈处没有注释造成的

  9. 经典c程序100例==91--100

    [程序91] 题目:时间函数举例1 1.程序分析: 2.程序源代码: #include "stdio.h" #include "time.h" void mai ...

  10. 第05组 Alpha冲刺 (1/6)

    .th1 { font-family: 黑体; font-size: 25px; color: rgba(0, 0, 255, 1) } #ka { margin-top: 50px } .aaa11 ...