Problem Solving/LeetCode

2023.09.18 Today's Challenge

fabichoi 2023. 9. 18. 23:45

https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

매우 간단했던 문제!!!

class Solution:
    def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:
        d = {}
        idx = 0
        for m in mat:            
            d[idx] = sum(m)
            idx += 1
        d = sorted(d.items(), key=lambda item: item[1])
        res = []
        for r in d:
            res.append(r[0])
        return res[:k]
반응형