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][0] for i in range(len(total_list))]
return answer
|
cs |
list comprehension과 sort를 사용하시면 됩니더
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2529. Maximum Count of Positive Integer and Negative Integer (0) | 2023.01.10 |
---|---|
leetcode 2485. Find the Pivot Integer (0) | 2023.01.10 |
leetcode 2315. Count Asterisks (0) | 2023.01.09 |
leetcode 2367. Number of Arithmetic Triplets (0) | 2023.01.08 |
백준 10203 Count Vowels (0) | 2023.01.07 |
댓글