# Leetcode 605. Can Place Flowers ###### tags: `Leetcode(JAVA)` 題目 : https://leetcode.com/problems/can-place-flowers/ 。 想法 : 根據題意完成即可。 時間複雜度 : O(n)。 程式碼 : (JAVA) ``` class Solution { public boolean canPlaceFlowers(int[] flowerbed, int n) { int l=flowerbed.length, cnt=0; for(int i=0 ; i<l ; i++){ int i1 = (i-1 < 0 ? 0 : flowerbed[i-1]); int i2 = flowerbed[i]; int i3 = (i+1 >= l ? 0 : flowerbed[i+1]); //System.out.printf("%d : %d %d %d\n", i, i1, i2, i3); if(i1 == 0 && i2 == 0 && i3 == 0){ flowerbed[i]=1; cnt++; } } return cnt >= n ? true : false; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up