2410. Maximum Matching of Players With Trainers

2023. 1. 7. 20:56Algorithm/Leetcode, Lintcode, HackerRank, etc.

    목차
반응형

Intuition

Approach

Complexity

  • Time complexity:

    O(NlogN)

  • Space complexity:

    O(1)

Code

class Solution:
    def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int:

        cnt = 0
        trainers.sort()
        for player in sorted(players):
            idx = bisect.bisect_left(trainers, player)

            if idx >= len(trainers):
                break

            trainers.pop(idx)
            cnt += 1

        return cnt

반응형