498 Diagonal Traverse

1. Question

Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image.

Example:

Input:

[
 [ 1, 2, 3 ],
 [ 4, 5, 6 ],
 [ 7, 8, 9 ]
]

Output:
  [1,2,4,7,5,3,6,8,9]

Explanation:

2. Implementation

3. Time & Space Complexity

时间复杂度O(mn), 空间复杂度O(mn)

Last updated

Was this helpful?