@@ -0,0 +1,952 @@
+// O(n%5E2) time and O(1) space complexity.%0A//%0A// Idea of the solution is rotating a ring and 4 elements at a time, this allows to store one of%0A// them in %60tmp%60 and overwrite them with a rotated value.%0A//%0A// Be careful, %60i%60 is treated in %60rotateRing%60 as an offset (from 0 to side length),%0A// not from start to end.%0A// Also need to be very careful with indices of 4 rotating elements.%0A//%0Aclass Solution %7B%0A  public void rotate(int%5B%5D%5B%5D matrix) %7B%0A    if (matrix.length == 0) return;%0A    int n = matrix.length;%0A    for (int i = 0; i %3C n/2; i++) %7B%0A      rotateRing(matrix, i, n - i - 1);%0A    %7D%0A  %7D%0A%0A  private void rotateRing(int%5B%5D%5B%5D matrix, int start, int end) %7B%0A    for (int i = 0; i %3C end - start; i++) %7B%0A      int tmp = matrix%5Bstart%5D%5Bstart + i%5D;%0A      matrix%5Bstart%5D%5Bstart + i%5D = matrix%5Bend - i%5D%5Bstart%5D;%0A      matrix%5Bend - i%5D%5Bstart%5D = matrix%5Bend%5D%5Bend - i%5D;%0A      matrix%5Bend%5D%5Bend - i%5D = matrix%5Bstart + i%5D%5Bend%5D;%0A      matrix%5Bstart + i%5D%5Bend%5D = tmp;%0A    %7D%0A  %7D%0A%7D%0A

add solution