leet code 605 Can Place Flowers

来源:互联网 发布:域名找回 编辑:程序博客网 时间:2024/06/08 20:08
class Solution {    public boolean canPlaceFlowers(int[] flowerbed, int n) {        int count=0;        for(int i=0;i<flowerbed.length && count<n;i++){            if(flowerbed[i]==0  && (i == 0 || flowerbed[i-1]==0) && (i == flowerbed.length-1 || flowerbed[i+1]==0)){                flowerbed[i]=1;                count++;            }        }        return count==n;    }}

原创粉丝点击