Posted on 2023-11-22 18:22
Uriel 閱讀(35)
評論(0) 編輯 收藏 引用 所屬分類:
模擬 、
閑來無事重切Leet Code
按從左下到右上斜著輸出一個二維數(shù)組的值(數(shù)組有缺失值)
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])]