1class Solution {2public char[][] rotateTheBox(char[][] box) {3int row = box.length, col = box[0].length;4char[][] res = new char[col][row];5// rotate first, then drop6for (int i = 0; i < row; i++) {7for (int j = 0; j < col; j++) {8res[j][i] = box[row - 1 - i][j];9}10}1112for (int i = col - 1; i >= 0; i--) {13for (int j = 0; j < row; j++) {14if (res[i][j] == '#') {15int curRow = i;16while (curRow + 1 < col && res[curRow + 1][j] == '.') {17curRow++;18}19if (curRow != i) {20res[curRow][j] = '#';21res[i][j] = '.';22}23}24}25}26return res;27}28}