Reuse 870
Intuition\r\n Describe your first thoughts on how to solve this problem. \r\nThis is the same \u7530\u5FCC\u8CFD\u99AC question as 870.\r\n# Approach\r\n Descri
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\nThis is the same \u7530\u5FCC\u8CFD\u99AC question as 870.\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\nJust reuse the solution\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n$$O(nlogn)$$\r\n- Space complexity:\r\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\r\n$$O(n)$$\r\n# Code\r\n```python3 []\r\nfrom typing import List\r\n\r\n\r\nclass Solution:\r\n    def advantageCount(self, nums1: List[int], nums2: List[int]) -> List[int]:\r\n        nums1.sort()\r\n        nums2_indices = sorted(enumerate(nums2), key = lambda x: x[1])\r\n        p1, p2, l1 = len(nums1)-1, len(nums1)-1, 0\r\n        result = [-1 for i in range(len(nums1))]\r\n        while p1 >= l1:\r\n            if nums1[p1] > nums2_indices[p2][1]:\r\n                result[nums2_indices[p2][0]] = nums1[p1]\r\n                p1 -= 1\r\n            else:\r\n                result[nums2_indices[p2][0]] = nums1[l1]\r\n                l1 += 1\r\n            p2 -= 1\r\n        return result\r\n    \r\n    def maximizeGreatness(self, nums: List[int]) -> int:\r\n        perm = self.advantageCount(nums, nums)\r\n        result = 0\r\n        for p, n in zip(perm, nums):\r\n            if p > n: result += 1\r\n        return result\r\n```
['Python3']