LeetCode - Algorithms - 2418. Sort the People

Problem

2418. Sort the People

Python

1
2
3
4
5
6
7
8
9
10
11
12
import collections

class Solution:
def sortPeople(self, names: List[str], heights: List[int]) -> List[str]:
d = dict()
for i in range(len(names)):
d[heights[i]] = names[i]
od = collections.OrderedDict(sorted(d.items(), reverse=True))
result = []
for key in od:
result.append(od[key])
return result

Submission Detail

  • 68 / 68 test cases passed.
  • Runtime: 331 ms, faster than 15.16% of Python3 online submissions for Sort the People.
  • Memory Usage: 14.4 MB, less than 89.07% of Python3 online submissions for Sort the People.