75-days-dsa-challenge

Ninja technique🥷 to ACE DSA Interviews.

View the Project on GitHub

48. Rotate Image 🌟🌟

O(N^2) Time and O(N^2) space Solution

O(N^2) Time O(1) Space Solution

Code

class Solution {
public:
    void rotate(vector<vector<int>>& matrix)
    {
        int n = matrix.size(),m = matrix[0].size();
        reverse(matrix.begin(), matrix.end());
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < m; j++)
                swap(matrix[i][j], matrix[j][i]);
        }
    }
};