Leetcode 1424. Diagonal Traverse II
Given a list of lists of integers, nums, return all elements of nums in diagonal order as shown in the below images.Example 1:
Input: nums = [,,]
Output:
Example 2:
Input: nums = [,,,,]
Output:
Example 3:
Input: nums = [,,,,]
Output:
Example 4:
Input: nums = []
Output:
Constraints:
1 <= nums.length <= 10^5
1 <= nums.length <= 10^5
1 <= nums <= 10^9
There at most 10^5 elements in nums.
class Solution:
def findDiagonalOrder(self, nums: List]) -> List:
result = []
if nums == None or len(nums) == 0:
return result
hashmap = collections.defaultdict(list)
m = len(nums)
for i in range(m):
for j in range(len(nums)):
hashmap.append(nums)
for k in sorted(hashmap.keys()):
temp = hashmap
temp = temp[::-1]
result += temp
return result
页:
[1]