C++ Solution


  • 0
    D

    经过我的观察,新的图像的第i行元素都是由第i列的元素按从底到顶的顺序组成的

    English by google translate :
    After my observation, the ith line of the new image consists of the elements of the ith column in the order from bottom to top

    My Source Code

    class Solution {
    public:
        void rotate(vector<vector<int>>& matrix) {
            
            vector<vector<int>> tmp;
            
            for(int j = 0; j < matrix[0].size(); j++)
            {
                vector<int> a;
                tmp.push_back(a);
                
                for(int i = 0; i < matrix.size(); i++)
                    tmp[j].push_back(matrix[i][j]);
            }
                    
            matrix.clear();
            for(int i = 0; i < tmp.size(); i++)
            {
                vector<int> a;
                matrix.push_back(a);
                for(int j = tmp[i].size() - 1; j >= 0; j--)
                    matrix[i].push_back(tmp[i][j]);
            }
            
        }
    };
    

Log in to reply
 

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