IT/코딩테스트
[Leetcode] 2418. Sort the People
이주디
2024. 3. 2. 23:02
728x90
https://leetcode.com/problems/sort-the-people
Sort the People - LeetCode
Can you solve this real interview question? Sort the People - You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n. For each index i, names[i] and heights[i] denote the name
leetcode.com
class Solution:
def sortPeople(self, names: List[str], heights: List[int]) -> List[str]:
people = []
for i in range(len(names)):
people.append((names[i], heights[i]))
print(people)
people = sorted(people, key=lambda x: x[1], reverse=True)
result = []
for person in people:
result.append(person[0])
return result
728x90