본문 바로가기
python-algorithm

leetcode 2418. Sort the People

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

https://leetcode.com/problems/sort-the-people/description/

 

1
2
3
4
5
6
class Solution:
    def sortPeople(self, names: List[str], heights: List[int]) -> List[str]:
        total_list=  [ [names[i],heights[i]] for i in range(len(names)) ]
        total_list.sort(key=lambda x: x[1], reverse=True)
        answer = [total_list[i][0for i in range(len(total_list))]
        return answer
cs

list comprehension과 sort를 사용하시면 됩니더

반응형

댓글