leetcode1341

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode1341相关的知识,希望对你有一定的参考价值。

 1 class Solution:
 2     def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:
 3         m = len(mat)
 4         n = len(mat[0])
 5         counter = [0] * m
 6         for i in range(m):
 7             for j in range(n):
 8                 if mat[i][j] == 1:
 9                     counter[i] += 1
10                 else:
11                     break
12         #print(counter)
13         at = []
14         for i in range(len(counter)):
15             at.append((i,counter[i]))
16         at = sorted(at,key=lambda x:(x[1],x[0]))
17         result = []
18         for x in range(k):
19             result.append(at[x][0])
20         return result

算法思路:排序。

以上是关于leetcode1341的主要内容,如果未能解决你的问题,请参考以下文章

[P1341]无序字母对 (欧拉回路)

P1341 无序字母对(欧拉回路)

Aladdin and the Flying Carpet (LightOJ - 1341)简单数论算术基本定理分解质因数(未完成)

LightOJ1341 Aladdin and the Flying Carpet

leetcode_1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_[二维前缀和](代码片段

<LeetCode OJ> 337. House Robber III