A simple C solution[Accepted]


  • 0
    B
    bool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n) {
        int count=0;
        if(flowerbed[0]!=1&&flowerbed[1]!=1){count++;flowerbed[0]=1;}
        for(int i=2;i<flowerbedSize-1;i++){
            if(flowerbed[i]!=1&&flowerbed[i-1]!=1&&flowerbed[i+1]!=1){count++;flowerbed[i]=1;}
        }
        if(flowerbed[flowerbedSize-2]!=1&&flowerbed[flowerbedSize-1]!=1){count++;}
        return count>=n?true:false;
    }
    

Log in to reply
 

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