| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | namespace LeetCode.Algorithms.RotatingTheBox; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class RotatingTheBoxMatrix : IRotatingTheBox |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Time complexity - O(n * m) |
| | 19 | | /// Space complexity - O(n * m) |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="box"></param> |
| | 22 | | /// <returns></returns> |
| | 23 | | public char[][] RotateTheBox(char[][] box) |
| 3 | 24 | | { |
| 3 | 25 | | var m = box.Length; |
| 3 | 26 | | var n = box[0].Length; |
| | 27 | |
|
| 3 | 28 | | var result = new char[n][]; |
| | 29 | |
|
| 32 | 30 | | for (var i = 0; i < n; i++) |
| 13 | 31 | | { |
| 13 | 32 | | result[i] = new char[m]; |
| 13 | 33 | | } |
| | 34 | |
|
| 18 | 35 | | for (var i = 0; i < m; i++) |
| 6 | 36 | | { |
| 70 | 37 | | for (var j = 0; j < n; j++) |
| 29 | 38 | | { |
| 29 | 39 | | result[j][m - i - 1] = box[i][j]; |
| 29 | 40 | | } |
| 6 | 41 | | } |
| | 42 | |
|
| 18 | 43 | | for (var j = 0; j < m; j++) |
| 6 | 44 | | { |
| 6 | 45 | | var emptyRow = n - 1; |
| | 46 | |
|
| 70 | 47 | | for (var i = n - 1; i >= 0; i--) |
| 29 | 48 | | { |
| 29 | 49 | | switch (result[i][j]) |
| | 50 | | { |
| | 51 | | case '#': |
| 14 | 52 | | result[i][j] = '.'; |
| 14 | 53 | | result[emptyRow][j] = '#'; |
| 14 | 54 | | emptyRow--; |
| 14 | 55 | | break; |
| | 56 | | case '*': |
| 5 | 57 | | emptyRow = i - 1; |
| 5 | 58 | | break; |
| | 59 | | } |
| 29 | 60 | | } |
| 6 | 61 | | } |
| | 62 | |
|
| 3 | 63 | | return result; |
| 3 | 64 | | } |
| | 65 | | } |