605. Can Place Flowers Easy

@problem@discussion
#Array#Greedy



1/**
2 * [605] Can Place Flowers
3 *
4 * You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.
5 * Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule.
6 *  
7 * Example 1:
8 * Input: flowerbed = [1,0,0,0,1], n = 1
9 * Output: true
10 * Example 2:
11 * Input: flowerbed = [1,0,0,0,1], n = 2
12 * Output: false
13 *  
14 * Constraints:
15 * 
16 * 	1 <= flowerbed.length <= 2 * 10^4
17 * 	flowerbed[i] is 0 or 1.
18 * 	There are no two adjacent flowers in flowerbed.
19 * 	0 <= n <= flowerbed.length
20 * 
21 */
22pub struct Solution {}
23
24// problem: https://leetcode.com/problems/can-place-flowers/
25// discuss: https://leetcode.com/problems/can-place-flowers/discuss/?currentPage=1&orderBy=most_votes&query=
26
27// submission codes start here
28
29impl Solution {
30    pub fn can_place_flowers(flowerbed: Vec<i32>, n: i32) -> bool {
31        false
32    }
33}
34
35// submission codes end
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_605() {
43    }
44}
45


Back
© 2025 bowen.ge All Rights Reserved.