498\. Diagonal Traverse

Medium

Given an `m x n` matrix `mat`, return _an array of all the elements of the array in a diagonal order_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/04/10/diag1-grid.jpg)

**Input:** mat = [[1,2,3],[4,5,6],[7,8,9]]

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

**Example 2:**

**Input:** mat = [[1,2],[3,4]]

**Output:** [1,2,3,4]

**Constraints:**

*   `m == mat.length`
*   `n == mat[i].length`
*   <code>1 <= m, n <= 10<sup>4</sup></code>
*   <code>1 <= m * n <= 10<sup>4</sup></code>
*   <code>-10<sup>5</sup> <= mat[i][j] <= 10<sup>5</sup></code>