zoukankan      html  css  js  c++  java
  • LeetCode: Rotate Image

    好麻烦的一道题,完全是算术。。少数次过

     1 class Solution {
     2 public:
     3     void rotate(vector<vector<int> > &matrix) {
     4         // Start typing your C/C++ solution below
     5         // DO NOT write int main() function
     6         int n = matrix.size();
     7         for (int i = 0; i < n/2; i++) {
     8             for (int j = i; j < n-1-i; j++) {
     9                 int tmp = matrix[i][j];
    10                 matrix[i][j] = matrix[n-1-j][i];
    11                 matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
    12                 matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
    13                 matrix[j][n-1-i] = tmp;
    14             }
    15         }
    16     }
    17 };

     C#

     1 public class Solution {
     2     public void Rotate(int[,] matrix) {
     3         int n = matrix.GetLength(0);
     4         for (int i = 0; i < n/2; i++) {
     5             for (int j = i; j < n-1-i; j++) {
     6                 int tmp = matrix[i, j];
     7                 matrix[i, j] = matrix[n-1-j, i];
     8                 matrix[n-1-j, i] = matrix[n-1-i, n-1-j];
     9                 matrix[n-1-i, n-1-j] = matrix[j, n-1-i];
    10                 matrix[j, n-1-i] = tmp;
    11             }
    12         }
    13     }
    14 }
    View Code
  • 相关阅读:
    Python day43 :pymysql模块/查询,插入,删除操作/SQL注入完全问题/事务/模拟登录注册服务器/视图/函数/存储过程
    docker
    Linux 05
    Linux04
    Linux 03
    Linux 02
    go语言
    go语言
    go语言
    Linux
  • 原文地址:https://www.cnblogs.com/yingzhongwen/p/3032618.html
Copyright © 2011-2022 走看看