# [48\. Rotate Image](https://leetcode.com/problems/rotate-image/) :::spoiler Solution ```cpp= class Solution { public: void rotate(vector<vector<int>>& matrix) { int n = matrix.size(); for(int i = 0; i < n; ++i) { for(int j = i; j < n; ++j) { swap(matrix[i][j], matrix[j][i]); } } for(int i = 0; i < n; i++) { reverse(matrix[i].begin(), matrix[i].end()); } } }; ``` - T: $O(M \cdot N)$ - S: $O(1)$ :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up