Python Very Simple Solution


  • 0

    Obviously for n plots, we can place (n-1)/2 flowers.

    class Solution(object):
        def canPlaceFlowers(self, flowerbed, n):
            """
            :type flowerbed: List[int]
            :type n: int
            :rtype: bool
            """
            ans = 0
            cnt = 1
            for plot in flowerbed:
                if plot == 0:
                    cnt += 1
                else:
                    ans += abs(cnt - 1) / 2
                    cnt = 0
            return ans + cnt / 2 >= n
    

  • 0
    T

    Nice.
    Much simpler than my code with same idea.


Log in to reply
 

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