diff --git a/src/main/java/Rotate Image b/src/main/java/Rotate Image new file mode 100644 index 0000000..15fad2a --- /dev/null +++ b/src/main/java/Rotate Image @@ -0,0 +1,50 @@ +-------------------------------------------------------------- +@Sayak +Rotate the image by 90 degrees (clockwise). +Given input matrix = +[ + [ 8, 1, 9,12], + [ 2, 4, 8,10], + [13, 3, 6, 7], + [18,14,12,16] +], + +rotate the input matrix in-place such that it becomes: +[ + [18,13, 2, 8], + [14, 3, 4, 1], + [12, 6, 8, 9], + [16, 7,10,12] +] + + The solution can be achieved int two steps: + 1) Transpose the matrix + 2) Reverse the matrix rows start<->end , start++, end-- + +-------------------------------------------------------------- + +class Solution { + public void rotate(int[][] matrix) { + + int n= matrix.length; + for(int i=0;i