• LeetCode Rotatelmage


    ---恢复内容开始---

    You are given an n x n 2D matrix representing an image.

    Ratate the image by 90 degrees(clockwise).

    Follow up:Could you do this in-place?

    分析如下:

    比较简单的一道题目。先沿着对角线(左下到右上)做对称变换,然后沿着竖直中心轴做对称变换。

    ---恢复内容结束---

    class Solution {

    public :

    void rotate(vector <vector<int>>&matrix ){

          if (matrix.empty())

                  return ;

    int n=matrix.size();

    //沿着对角线(左上到右下)做对称变换

    for (int k=0;k<n;k++)

    {

    for (int i=0;i<k;i++)

    {

    int tmp=matrix[k][i];

    matrix[k][i]=matrix[i][k];

    matrix[i][k]=tmp;

    }
    }

    //沿着竖直中心轴做对称变换

    for (int k=0;k<n;k++){

    int s=0;

    int t=n-1;

    while (s<t){

    int tmp=matrix[k][s];

    matrix[k][s]=matrix[k][s];

    matrix[k][t]=tmp;

    s++;

    t--;

    }

    }

    return ;

    }

    }

  • 相关阅读:
    01
    Django2
    Django01
    DS18B20时序解析,以及读出85原因诠释
    python字符串打印-不同方法vars
    2.对象属性
    1.excel-vba-对象
    搭建 eclipse,maven,tomcat 环境
    jsp include flush true
    oracle数据库基础
  • 原文地址:https://www.cnblogs.com/heruonan/p/8366275.html
Copyright © 2020-2023  润新知