Page tree
Skip to end of metadata
Go to start of metadata

25%, 54%

Queue Reconstruction by Height
class Solution:
    def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
        def s(t1, t2):
            if t1[0] < t2[0]:
                return 1    

            if t1[0] == t2[0] and t1[1] > t2[1]:
                return 1

            return -1

        new_list = sorted(people, key=functools.cmp_to_key(s))

        results = []
        for item in new_list:
            pos = item[1]

            results = results[0:pos] + [item] + results[pos:]
            
        return results



  • No labels