Posted on 2023-11-22 18:22
Uriel 阅读(20)
评论(0) 编辑 收藏 引用 所属分类:
模拟 、
闲来无事重切Leet Code
按从左下到右上斜着输出一个二维数组的值(数组有缺失值)
1 #1424
2 #Runtime: 724 ms (Beats 27.21%)
3 #Memory: 40.3 MB (Beats 41.50%)
4
5 class Solution(object):
6 def findDiagonalOrder(self, nums):
7 """
8 :type nums: List[List[int]]
9 :rtype: List[int]
10 """
11 ans = defaultdict(list)
12 for x in xrange(len(nums)):
13 for y in xrange(len(nums[x])):
14 ans[x + y].append(nums[x][y])
15 return [y for x in ans.keys() for y in reversed(ans[x])]