mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
cs: add “605. Can Place Flowers”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
7fb942c159
commit
c58830b483
1 changed files with 19 additions and 0 deletions
19
cs/can-place-flowers.cs
Normal file
19
cs/can-place-flowers.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
public class Solution {
|
||||||
|
public bool CanPlaceFlowers(int[] flowerbed, int n) {
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
int left = 0, right;
|
||||||
|
for (var i = 0; i < flowerbed.Length; ++i) {
|
||||||
|
right = (i + 1 < flowerbed.Length) ? flowerbed[i + 1] : 0;
|
||||||
|
|
||||||
|
if (left == 0 && flowerbed[i] == 0 && right == 0) {
|
||||||
|
++count;
|
||||||
|
left = 1;
|
||||||
|
} else {
|
||||||
|
left = flowerbed[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count >= n;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue