Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 531 Bytes

1337.md

File metadata and controls

21 lines (19 loc) · 531 Bytes

1319. Number of Operations to Make Network Connected

Solution 1 (time O(mn+mlog(m)), space O(m))

class Solution(object):
    def kWeakestRows(self, mat, k):
        """
        :type mat: List[List[int]]
        :type k: int
        :rtype: List[int]
        """
        cnts = []
        for i in range(len(mat)):
            cnts.append((sum(mat[i]), i))
        cnts = sorted(cnts, key=lambda x:(x[0], x[1]))
        ans = []
        for i in range(k):
            ans.append(cnts[i][1])
        return ans