zoukankan      html  css  js  c++  java
  • Rotate Image

          题意是旋转正方形矩形。右旋90度,要求O(1)空间复杂度。

    // Rotate a round which top & left is topleft, bottom & right is bottomright.
    void rotate(vector<vector<int> > &matrix, size_t topleft, size_t bottomright)
    {
        for (size_t i = 0; i < bottomright - topleft; ++i)
        {
            int tmp = matrix[topleft][topleft + i];
     
            matrix[topleft][topleft + i] = matrix[bottomright - i][topleft];
            matrix[bottomright - i][topleft] = matrix[bottomright][bottomright - i];
            matrix[bottomright][bottomright - i] = matrix[topleft + i][bottomright];
            matrix[topleft + i][bottomright] = tmp;
        }
    }
     
    void rotate(vector<vector<int> > &matrix) 
    {
        size_t topleft = 0, bottomright = matrix.size() - 1;
     
        while (topleft < bottomright)
        {
            rotate(matrix, topleft, bottomright);
            ++topleft; --bottomright;
        }
    }
  • 相关阅读:
    vi命令大全
    理解proc文件系统
    读目录
    取得系统资源信息
    qtempinc
    我实现的一个正则表达式代码
    oracle内置函数大全
    STL算法
    unix基础教程
    两日期间的天数
  • 原文地址:https://www.cnblogs.com/codingmylife/p/2714432.html
Copyright © 2011-2022 走看看