亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

LeetCode[48] Rotate Image

sanyang / 3189人閱讀

LeetCode[48] Rotate Image

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

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

復(fù)雜度
O(N^2),O(1)

代碼

  public void rotate(int[][] matrix) {
        int n = matrix.length;
        for(int layer = 0; layer < n / 2; layer ++) {
            int start = layer;
            int end = n - 1 - start;
            for(int i = start; i < end; i ++) {
                int offset = i - start;
                int temp = matrix[start][i];
                //left to top;
                matrix[start][i] = matrix[end - offset][start];
                //bottom to left;
                matrix[end - offset][start] = matrix[end][end - offset];
                //right to bottm;
                matrix[end][end - offset] = matrix[i][end];
                //top to right;
                matrix[i][end] = temp; 
            }
        }

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/65293.html

相關(guān)文章

  • [LeetCode] 48. Rotate Image

    Problem You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which means you have to modify the input 2D mat...

    Warren 評論0 收藏0
  • leetcode 48 Rotate Image

    摘要:題目詳情這道題目要求我們對一個正方形矩陣進行順時針度的翻轉(zhuǎn)。并且要求不聲明額外的空間,不能新建二維數(shù)組。輸入數(shù)組旋轉(zhuǎn)后的輸入數(shù)組想法這道題因為要求在位。所以我們需要找到一種解法,使得每次操作都是交換兩個元素的位置,最后實現(xiàn)整個矩陣的旋轉(zhuǎn)。 題目詳情 You are given an n x n 2D matrix representing an image.Rotate the ima...

    kgbook 評論0 收藏0
  • leetcode48 Rotate Image 90度旋轉(zhuǎn)數(shù)組

    摘要:每一次的旋轉(zhuǎn),其實都是正方形上的四個元素之間的相互替換。所以本質(zhì)上我們只需遍歷每種長度正方形上的一條邊,就可以完成這個正方形的旋轉(zhuǎn)。最后實現(xiàn)整個數(shù)組矩陣的旋轉(zhuǎn)代表正方形的起始位置,即,,即,代表當(dāng)前正方形上的一條邊上的一個點。 題目要求 You are given an n x n 2D matrix representing an image. Rotate the image b...

    melody_lql 評論0 收藏0
  • leetcode 部分解答索引(持續(xù)更新~)

    摘要:前言從開始寫相關(guān)的博客到現(xiàn)在也蠻多篇了。而且當(dāng)時也沒有按順序?qū)懍F(xiàn)在翻起來覺得蠻亂的。可能大家看著也非常不方便。所以在這里做個索引嘻嘻。順序整理更新更新更新更新更新更新更新更新更新更新更新更新更新更新更新更新 前言 從開始寫leetcode相關(guān)的博客到現(xiàn)在也蠻多篇了。而且當(dāng)時也沒有按順序?qū)憽F(xiàn)在翻起來覺得蠻亂的??赡艽蠹铱粗卜浅2环奖?。所以在這里做個索引嘻嘻。 順序整理 1~50 1...

    leo108 評論0 收藏0
  • [Leetcode] Rotate Image 旋轉(zhuǎn)圖片

    摘要:交換法復(fù)雜度時間空間思路為了實現(xiàn)這題,我們要用交換的方法,順序是左上先和左下交換,然后左上和右下交換,然后左上和右上交換。和類似,我們通過圈數(shù)來控制內(nèi)外的順序。代碼計算圈數(shù)左上和左下交換左上和右下交換左上和右上交換 Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image...

    Brenner 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<