Untitled

Anonymous
Plain Text
08/25/2025 2:34 PM
1.5 KB
21
Indexable
Never
class Solution:
    def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:
        direction = 1
        m = len(mat)
        n = len(mat[0])
        pos_x = 0
        pos_y = 0
        road_list = []
        print(f"m={m} n={n}")
        while 1:
            print(f"direction={direction}")
            print(f"pos_x={pos_x} pos_y={pos_y}")
            print(f"value={mat[pos_y][pos_x]}")
            road_list.append(mat[pos_y][pos_x])
            if pos_x == n - 1 and pos_y == m - 1:
                break
            if direction == 1:
                if pos_y == 0:
                    if pos_x < m - 1:
                        print("pos0")
                        pos_x += 1
                    else:
                        print("pos1")
                        pos_y += 1
                    direction = 0
                else:
                    print("pos2")
                    pos_x += 1
                    pos_y -= 1
            else:
                if pos_x == 0:
                    if pos_y < m - 1:
                        print("pos3")
                        pos_y += 1
                    else:
                        print("pos4")
                        pos_x += 1
                    direction = 1
                elif pos_y == m - 1:
                    print("pos5")
                    pos_x += 1
                else:
                    print("pos6")
                    pos_x -= 1
                    pos_y += 1
            
        
        return road_list
Editor is loading...
Leave a Comment