8 ARTS打卡第八周(2019-09-17)

2019-10-04  本文已影响0人  无敌的潘大帅

Algorithm

本周算法:48.旋转图像(未解出)
题解思路:使用两次翻转来实现旋转效果,首先第一次翻转,将对应的行数字移动至它旋转后应在的数组中,但是位置并不一定正确,比如7原先在索引为2的数组,通过翻转将它移动至索引为0的数组中。第二次翻转则将每个一维数组进行反转操作,将对应数字移动到正确的位置。

题解代码

class Solution {
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i = 0; i < n; i ++) {
            for (int j = i; j < n; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }
        
        for (int i = 0; i < n; i ++) {
           for (int j = 0; j < n / 2; j++) {
            int tmp = matrix[i][j];
            matrix[i][j] = matrix[i][n - j - 1];
            matrix[i][n - j - 1] = tmp;
           }
        }
    }
}

Review

Tip

以下是关于cp命令的使用
cp usage
\cp -rf file1.txt file2.txt
cp前加上\ 在存在相同文件时,进行覆盖而不提示
-r -R Copy directories recursively. 递归复制文件及文件夹
-f If an existing destination file cannot be opened, remove it and try again. This option has no effect if the -n/--no-clobber option is used. However, it applies independently of -i/--interactive; neither option cancels the effect of the other,如果目标文件存在,强制将其删除,并重新执行复制操作。

Share

这是一篇关于FTP服务器安装的过程,我已根据这篇文章成功搭建出对应的FTP服务器。
ftp安装

上一篇下一篇

猜你喜欢

热点阅读