首页 > 其他 > 详细

leetcode1329

时间:2020-01-26 09:40:53      阅读:85      评论:0      收藏:0      [点我收藏+]
 1 class Solution:
 2     def diagonalSort(self, mat: List[List[int]]) -> List[List[int]]:
 3         m = len(mat)
 4         n = len(mat[0])
 5 
 6         i,j = m-1,0
 7         while i != 0 or j != n-1:
 8             x,y = i,j
 9             temp = []
10             while x < m and y < n:
11                 temp.append(mat[x][y])
12                 if x < m:
13                     x += 1
14                 if y < n:
15                     y += 1
16             temp.sort()
17             x,y,z = i,j,0
18             while x < m and y < n:
19                 mat[x][y] = temp[z]
20                 if x < m:
21                     x += 1
22                 if y < n:
23                     y += 1
24                 z += 1
25             if i > 0:
26                 i -= 1
27                 j = 0
28             else:
29                 i = 0
30                 if j < n:
31                     j += 1
32         return mat

算法思路:二维数组遍历。

leetcode1329

原文:https://www.cnblogs.com/asenyang/p/12233716.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!