这题需要搞清楚矩阵元素的位置关系,尤其是副对角线元素,沿着副对角线元素

 void rotateImage(vector<vector<int>> &matrix)
{
int n = matrix.size();
//沿着副对角线翻转
for (int i = ; i < n;i++)
for (int j = ; j < n - i; j++)
{
swap(matrix[i][j], matrix[n - - j][n - - i]);
}
//沿着水平中线翻转
for (int i = ; i < n/;i++)
for (int j = ; j < n; j++)
{
swap(matrix[i][j], matrix[n - - i][j]);
}
}

leetcode 之Rotate Image(8)的更多相关文章

  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] 61. Rotate List 旋转链表

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

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

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

  4. 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  ...

  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. LeetCode 48 Rotate Image(2D图像旋转问题)

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

  7. 【LeetCode】 Rotate List 循环链表

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

  8. [LeetCode] 189. Rotate Array 旋转数组

    Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: ...

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

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

  10. [leetcode 48] rotate image

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

随机推荐

  1. ARC077D 11 组合数

    ---题面--- 题解: 做这道题的时候zz了,,,, 写了个很复杂的式子,然而后面重新想就发现很简单了. 考虑用总的情况减去重复的. 假设唯一重复的两个数的位置分别是l和r,那么唯一会导致重复的方案 ...

  2. 解析Fetch实现请求数据

    一 序言 在 传统Ajax 时代,进行 API 等网络请求都是通过XMLHttpRequest或者封装后的框架进行网络请求,然而配置和调用方式非常混乱,对于刚入门的新手并不友好.今天我们介绍的Fetc ...

  3. LOJ2537:[PKUWC2018]Minimax——题解

    https://loj.ac/problem/2537 参考了本题在网上能找到的为数不多的题解. 以及我眼睛瞎没看到需要离散化,还有不开longlong见祖宗. ——————————————————— ...

  4. Codeforces Round #345 (Div. 2) A

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. DOM用TagName操作标签

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  6. ACM2066

    题目原址:http://acm.hdu.edu.cn/showproblem.php?pid=2066 大神必须飘过,我在这个题目里面学到了太多太多了.我提交了十六次,错了十二次,反复了这么久才解决内 ...

  7. [技巧篇]14.据说SSH框架需要的监听器,IntrospectorCleanupListener

    开发这么久,我也没有使用过IntrospectorCleanupListener监听器,今天偶尔看到一篇文章,虽然没有怎么读懂,也不太理解,但是好像给官方提供一些解释!给自己留一个备注,多点东西因为没 ...

  8. Python爬虫学习笔记之极限滑动验证码的识别

    代码: import time from io import BytesIO from PIL import Image from selenium import webdriver from sel ...

  9. maven项目执行run as/maven install时提示找不到包

    选中项目,右键 右键项目->MAVEN->Update Project,如下图 点击ok,clean相关项目,再打包.如果还是不行看一下你jdk 的版本和你编译的版本是否一致

  10. 图论:最短路-SPFA

    该算法由Bellman-Ford算法演变过来,首先介绍一下Bellman-Ford算法 最短路最多经过n-1个点,可以用n-1轮松弛操作来得到 ;i<n;i++) d[i]=INF; d[]=; ...