public void rotate(int[][] matrix) {
    validateInput(matrix);

    int length = matrix.length;
    for (int i = 0; i < length / 2; ++i) {
      int first = i;
      int last = length - 1 - i;
      for (int j = first; j < last; ++j) {
        int offset = j - first;
        int top = matrix[first][j];
        moveLeftToTop(matrix, first, last, j, offset);
        moveBottomToLeft(matrix, first, last, offset);
        moveRithToBottom(matrix, last, j, offset);
        moveTopToRight(matrix, last, j, top);
      }
    }
  }
Iterative algorithm to solve this problem. This solution is based on move 4 positions per
iteration. With this approach we can reduce the complexity order in space terms from O(N^2) to
O(1). In time terms, the complexity order is O(N^2) where N is the height or width of the
matrix.
src/main/java/com/github/pedrovgs/problem54/RotateMatrix.java