|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author openset <[email protected]> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](../maximum-points-you-can-obtain-from-cards "Maximum Points You Can Obtain from Cards") |
| 9 | + |
| 10 | +[Next >](../constrained-subset-sum "Constrained Subset Sum") |
| 11 | + |
| 12 | +## [1424. Diagonal Traverse II (Medium)](https://leetcode.com/problems/diagonal-traverse-ii "对角线遍历 II") |
| 13 | + |
| 14 | +Given a list of lists of integers, <code>nums</code>, return all elements of <code>nums</code> in diagonal order as shown in the below images. |
| 15 | +<p> </p> |
| 16 | +<p><strong>Example 1:</strong></p> |
| 17 | + |
| 18 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/04/08/sample_1_1784.png" style="width: 158px; height: 143px;" /></strong></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> nums = [[1,2,3],[4,5,6],[7,8,9]] |
| 22 | +<strong>Output:</strong> [1,4,2,7,5,3,8,6,9] |
| 23 | +</pre> |
| 24 | + |
| 25 | +<p><strong>Example 2:</strong></p> |
| 26 | + |
| 27 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/04/08/sample_2_1784.png" style="width: 230px; height: 177px;" /></strong></p> |
| 28 | + |
| 29 | +<pre> |
| 30 | +<strong>Input:</strong> nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]] |
| 31 | +<strong>Output:</strong> [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16] |
| 32 | +</pre> |
| 33 | + |
| 34 | +<p><strong>Example 3:</strong></p> |
| 35 | + |
| 36 | +<pre> |
| 37 | +<strong>Input:</strong> nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]] |
| 38 | +<strong>Output:</strong> [1,4,2,5,3,8,6,9,7,10,11] |
| 39 | +</pre> |
| 40 | + |
| 41 | +<p><strong>Example 4:</strong></p> |
| 42 | + |
| 43 | +<pre> |
| 44 | +<strong>Input:</strong> nums = [[1,2,3,4,5,6]] |
| 45 | +<strong>Output:</strong> [1,2,3,4,5,6] |
| 46 | +</pre> |
| 47 | + |
| 48 | +<p> </p> |
| 49 | +<p><strong>Constraints:</strong></p> |
| 50 | + |
| 51 | +<ul> |
| 52 | + <li><code>1 <= nums.length <= 10^5</code></li> |
| 53 | + <li><code>1 <= nums[i].length <= 10^5</code></li> |
| 54 | + <li><code>1 <= nums[i][j] <= 10^9</code></li> |
| 55 | + <li>There at most <code>10^5</code> elements in <code>nums</code>.</li> |
| 56 | +</ul> |
| 57 | + |
| 58 | +### Related Topics |
| 59 | + [[Sort](../../tag/sort/README.md)] |
| 60 | + [[Array](../../tag/array/README.md)] |
| 61 | + |
| 62 | +### Hints |
| 63 | +<details> |
| 64 | +<summary>Hint 1</summary> |
| 65 | +Notice that numbers with equal sums of row and column indexes belong to the same diagonal. |
| 66 | +</details> |
| 67 | + |
| 68 | +<details> |
| 69 | +<summary>Hint 2</summary> |
| 70 | +Store them in tuples (sum, row, val), sort them, and then regroup the answer. |
| 71 | +</details> |
0 commit comments