c++ code


  • 0
    M

    class Solution {
    public:
    bool canPlaceFlowers(vector<int>& flowerbed, int n) {
    int start=-2, sum=0, i=0;
    for(i=0; i<flowerbed.size(); i++)
    {
    if(flowerbed[i] == 1)
    {
    sum += ((i-1)-start-1)/2;
    start = i;
    }
    }
    sum += (i-start-1) / 2;

        return sum>=n;
    }
    

    };


Log in to reply
 

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