Rotate Image


  • 0
    M
    class Solution {
    public:
      
        void swap(int &a,int &b)
        {
            int temp =a;
            a = b;
            b= temp;
        }
        void transpose(vector<vector<int>>& a)
        {
            int n = a.size();
            for(int i=0;i<n;i++)
                 for(int j=0;j<i;j++)
                    swap(a[i][j],a[j][i]);
        }
        void mirror(vector<vector<int>>& a)
        {
            int n = a.size();
            for(int i=0;i<n;i++)
                 for(int j=0;j<n/2;j++)
                    swap(a[i][j],a[i][n-j-1]);
        }
        void rotate(vector<vector<int>>& a) {
            transpose(a);
            mirror(a);
        }
    };```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.