My Solution in C++


  • 0

    This is my solution in C++.

    class Solution {
    public:
        void rotate(std::vector<std::vector<int> > &matrix)
        {
    		std::size_t length = matrix.size();
            for (std::size_t i = 0; i != length / 2; ++i)
            {
                for (std::size_t j = i; j != length - 1 - i; ++j)
                {
                    std::swap(matrix[j][i], matrix[length - 1 - i][j]);
    				std::swap(matrix[length - 1 - i][j], matrix[length - 1 - j][length - 1 - i]);
    				std::swap(matrix[length - 1 - j][length - 1 - i], matrix[i][length - 1 - j]);
                }
            }
        }
    };

Log in to reply
 

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