Rotate Image
Last updated
Was this helpful?
Last updated
Was this helpful?
You are given an n x n 2D matrix
representing an image, rotate the image by 90 degrees (clockwise).
You have to rotate the image , which means you have to modify the input 2D matrix directly. DO NOTallocate another 2D matrix and do the rotation.
Approach1:
This does not qualify as being intuitive but once you know it, it will spring up to mind every time you will need some form of array rotation. We first transpose the matrix and then we reverse each row.
Time: O(n2) Space: O(1)