inverted index using python


  • 0
    F
        def findShortestSubArray(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            from collections import defaultdict
            inverted_index = defaultdict(list)
            for i, num in enumerate(nums):
                inverted_index[num].append(i)
            degree = max(map(len, inverted_index.values()))
            result = min(value[-1] - value[0] for value in inverted_index.values() if len(value) == degree)
            return result + 1

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.