网站备案怎么在工信部信息核验,郴州新网交友信息,直播网站建设需要什么软件有哪些,免费做网站网站有人哪些假设有一个很长的花坛#xff0c;一部分地块种植了花#xff0c;另一部分却没有。可是#xff0c;花不能种植在相邻的地块上#xff0c;它们会争夺水源#xff0c;两者都会死去。
给你一个整数数组 flowerbed 表示花坛#xff0c;由若干 0 和 1 组成#xff0c;其中 0 …假设有一个很长的花坛一部分地块种植了花另一部分却没有。可是花不能种植在相邻的地块上它们会争夺水源两者都会死去。
给你一个整数数组 flowerbed 表示花坛由若干 0 和 1 组成其中 0 表示没种植花1 表示种植了花。另有一个数 n 能否在不打破种植规则的情况下种入 n 朵花能则返回 true 不能则返回 false 。
输入flowerbed [1,0,0,0,1], n 1
输出true
class Solution {public boolean canPlaceFlowers(int[] flowerbed, int n) {int[] anew int[flowerbed.length2];System.arraycopy(flowerbed,0,a,1,flowerbed.length);for(int i1;iflowerbed.length;i){if(a[i-1]0a[i]0a[i1]0){a[i]1;n--;}}return n0;}
}