Leetcode 1972 Solution

This article provides solution to leetcode question 1972 (rotating-the-box)

https://leetcode.com/problems/rotating-the-box

Solution

class Solution:
    def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:
        m = len(box)
        n = len(box[0])

        for i in range(m):
            l = 0
            r = 0
            while r < n:
                if box[i][r] == ".":
                    box[i][l], box[i][r] = box[i][r], box[i][l]
                    l += 1
                elif box[i][r] == "*":
                    l = r + 1
                r += 1

        ans = [['.' for _ in range(m)] for _ in range(n)]
        for i in range(m):
            for j in range(n):
                ans[j][m - 1 - i] = box[i][j]
        return ans