-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c1f18c4
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[MESSAGES CONTROL] | ||
disable=C0114,C0103,C0115,C0116 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ruff.lint.ignore": [ | ||
"C0114", | ||
"E741" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# https://leetcode.com/problems/rotating-the-box | ||
from typing import List | ||
|
||
|
||
class Solution: | ||
def rotate_the_box(self, box: List[List[str]]) -> List[List[str]]: | ||
|
||
ROWS = len(box) | ||
COLS = len(box[0]) | ||
|
||
for i in range(ROWS): | ||
right = COLS - 1 | ||
left = right - 1 | ||
while right >= 0 and left >= 0: | ||
|
||
right_val = box[i][right] | ||
left_val = box[i][left] | ||
|
||
# Ensure that the right spot is a valid spot we | ||
# can swap a value with | ||
if right_val != ".": | ||
right -= 1 | ||
left -= 1 | ||
elif left_val == ".": | ||
left -= 1 | ||
elif left_val == "#": | ||
box[i][right] = "#" | ||
box[i][left] = "." | ||
right -= 1 | ||
left -= 1 | ||
elif left_val == "*": | ||
left -= 1 | ||
right = left | ||
|
||
transposed_box = [[None for _ in range(ROWS)] for _ in range(COLS)] | ||
for i in range(ROWS): | ||
for j in range(COLS): | ||
transposed_box[j][i] = box[i][j] | ||
|
||
rotated_box = [row[::-1] for row in transposed_box] | ||
|
||
return rotated_box | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
test_case_1 = [["#", ".", ".", ".", "#"]] | ||
test_case_2 = [["#", ".", "*", "."], ["#", "#", "*", "."]] | ||
|
||
cls = Solution() | ||
cls.rotate_the_box(box=test_case_2) |