Exact same solution, accepted in python3 but not in python2.7! Any reasons?


  • 0
    S
    class Solution(object):
        def kEmptySlots(self, flowers, k):
            """
            :type flowers: List[int]
            :type k: int
            :rtype: int
            """
            days = [0]*len(flowers)
            for day,flower in enumerate(flowers):
                days[flower-1] = day
            left = 0
            right = k + 1
            res = None
            while right < len(days):
                for i in range(left+1, right):
                    if days[i] < days[left] or days[i] < days[right]:
                        left = i
                        right = i + k + 1
                        break
                else:
                    temp = max(days[left], days[right])+1
                    res = min(temp, res) if res else temp
                    left = right
                    right = left + k + 1
            return res if res else -1
    

Log in to reply
 

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