Advertisement
kosievdmerwe

406

Jun 29th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. class Solution:
  2.     def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
  3.         ps = sorted(people, key=lambda p: (-p[0],p[1]))
  4.         ans = []
  5.         for p in ps:
  6.             num_b = 0
  7.             idx = 0
  8.             for i in range(len(ans)):
  9.                 idx = i
  10.                 if p[1] == num_b:
  11.                     break
  12.                 if p[0] <= ans[i][0]:
  13.                     num_b += 1
  14.             else:
  15.                 idx = len(ans)
  16.             ans.insert(idx, p)
  17.         return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement