Skip to content

Latest commit

 

History

History
16 lines (16 loc) · 398 Bytes

棕榈树.md

File metadata and controls

16 lines (16 loc) · 398 Bytes
class Solution {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int i=0,count = 0;
        while(i<flowerbed.length){
            if(flowerbed[i]==0&&(i==0||flowerbed[i-1]==0)
            &&(i==flowerbed.length-1||flowerbed[i+1]==0)){
                flowerbed[i] = 1;
                count++;
            }
            i++;
        }
        return count>=n;
    }
}