Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc1b8688

Browse files
authored
Create 605-can-place-flowers.js
Solved can-place-flowers in JS.
1 parentc17e82c commitc1b8688

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// time complexity is O(n).
2+
3+
varcanPlaceFlowers=function(flowerbed,n){
4+
5+
for(leti=0;i<flowerbed.length;i++){
6+
if(flowerbed[i]===0){
7+
if((flowerbed[i-1]===0&&flowerbed[i+1]===0)||
8+
(flowerbed[i-1]===undefined&&flowerbed[i+1]===0)||
9+
(flowerbed[i+1]===undefined&&flowerbed[i-1]===0)||
10+
(flowerbed[i-1]===undefined&&flowerbed[i+1]===undefined&&flowerbed[i]===0)){
11+
12+
flowerbed[i]=1;
13+
n--;
14+
}
15+
}
16+
}
17+
18+
returnn>0 ?false :true;
19+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp