파비의 매일매일 공부기록

2023.09.18 Today's Challenge 본문

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]
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.09.20 Today's Challenge  (0) 2023.09.20
2023.09.19 Today's Challenge  (0) 2023.09.19
2023.09.17 Today's Challenge  (0) 2023.09.17
2023.09.16 Today's Challenge  (0) 2023.09.16
2023.09.15 Today's Challenge  (0) 2023.09.15
Comments