본문 바로가기
python-algorithm

leetcode 2545. Sort the Students by Their Kth Score

by 무적김두칠 2023. 1. 27.

https://leetcode.com/problems/sort-the-students-by-their-kth-score/description/

 

Sort the Students by Their Kth Score - LeetCode

Sort the Students by Their Kth Score - There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matr

leetcode.com

 

1
2
3
class Solution:
    def sortTheStudents(self, score: List[List[int]], k: int-> List[List[int]]:
        return sorted(score, key= lambda x: -x[k])
cs

lambda를 활용해서 정렬해주시면 쉽게 됩니다 
큰 순서대로 정렬해야하니까 x[k] 앞에 마이너스를 붙입니다

반응형

댓글