diff --git a/reverseSubmatrix b/reverseSubmatrix new file mode 100644 index 0000000..14ee320 --- /dev/null +++ b/reverseSubmatrix @@ -0,0 +1,15 @@ +class Solution { + public int[][] reverseSubmatrix(int[][] grid, int x, int y, int k) { + for (int i = 0; i < k / 2; i++) { + int topRow = x + i; + int bottomRow = x + k - 1 - i; + for (int j = 0; j < k; j++) { + int col = y + j; + int temp = grid[topRow][col]; + grid[topRow][col] = grid[bottomRow][col]; + grid[bottomRow][col] = temp; + } + } + return grid; + } +}