Python3 自排序容器
Python自带有排序容器SortedList, SortedDict, SortedSet
下面以SortedSet为例,leetcode414
from sortedcontainers import SortedSet class Solution: def thirdMax(self, nums: List[int]) -> int: s=SortedSet() for x in nums: s.add(x) if len(s)>3: s.pop(0) return s[0] if len(s)==3 else s[-1]

浙公网安备 33010602011771号