当前位置:网站首页>leetcode 605. Can place flowers planting problem (simple)
leetcode 605. Can place flowers planting problem (simple)
2022-07-18 03:40:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= flowerbed.length <= 2 * 104
- flowerbed[i] by 0 or 1
- flowerbed There are no two adjacent flowers
- 0 <= n <= flowerbed.length
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
public class Solution {
public boolean canPlaceFlowers(int[] flowerbed, int n) {
if (n == 0) {
return true;
}
int count = 0;
int len = flowerbed.length;
for (int i = 0; i < len; i++) {
boolean left = i == 0 ? true : flowerbed[i - 1] == 0;
boolean right = i == len - 1 ? true : flowerbed[i + 1] == 0;
if (flowerbed[i] == 0 && left && right) {
count++;
flowerbed[i] = 2;
if (count >= n) {
return true;
}
}
}
return false;
}
}
Four 、 Summary notes
- 2022/7/15 Form the habit of recording at ordinary times , Because some sudden thoughts , You can forget your Kung Fu after eating a meal .
边栏推荐
- 两年CRUD,普通二本毕业,挑战三个月面试阿里,成功拿下offer定级P7!年薪50w
- DEVKIT-mpc5744p配置rtos
- Four sides Ali offer grading p82022 latest and most practical Ali 68 advanced interview questions to help you succeed in your interview!!
- PD-Server GRPC 接口图解
- UTONMOS:社交元宇宙如何构建数字世界
- LNMP architecture PHP installation
- 想找个大券商开户?现在通过手机股票开户是安全的吗?
- MySQL (III) router, MHA high availability
- DEVKIT-mpc5744p配置rtos
- Will the expired data of redis be deleted immediately? Great mystery
猜你喜欢
![[200 opencv routines] 230 LBP statistical histogram of feature description](/img/e8/477bf835984933db9ef0a49b76093b.png)
[200 opencv routines] 230 LBP statistical histogram of feature description

After 00, he graduated from Nanjing University and planned to be a special associate researcher. Netizens quarreled after picking out their papers

std::unique_ptr作为形参时的使用问题

go-zero微服务实战系列(五、缓存代码怎么写)
![leetcode:558. Quadtree intersection [quadtree DFS]](/img/ea/7048657a7106c749eb4a8b95b07733.png)
leetcode:558. Quadtree intersection [quadtree DFS]

慢 SQL 分析与优化

想成为精英级开发者?请逼自己养成这10个习惯

Award winning research | openeuler developer experience research questionnaire

数据传输:同构异IP数据源批量抽取实践

【C语言】静态&动态&文件通讯录(超万字)
随机推荐
“小白嘴”白山药是哪个县的特色农产品? 蚂蚁新村7月15日答案
聚簇索引和非聚簇索引
Google Earth engine (GEE) - random forest classification has mapped the detailed code of mangrove app in Guyana in 2000, 2010 and 2020
Chromium Threading and Task
PD server grpc interface diagram
Devsecops R & D security practice - Development
[Xingguang 04] 2022 deep learning GPU form
难道双非本科就一定进不了大厂?阿里技术四面+交叉面+HR面,成功拿到offer!!
BufferedInputStream字节缓存输入流和缓存流的效率测试_复制文件
Euler talk | developer community experience bureau starts at about 19:30 on July 14
Looking for a big brokerage to open an account? Is it safe to open an account through mobile stock now?
TiKV & TiFlash 加速复杂业务查询
论文学习(一)——MWP-BERT: Numeracy-Augmented Pre-training for Math WordProblem Solving
Devkit mpc5744p configuring RTOS
Want to be an elite developer? Please force yourself to form these 10 habits
torch. nn. Use of ctcloss()
网站漏洞修复服务商讲解越权漏洞的原因
"Xiaobaizui" white yam is the characteristic agricultural product of which county? Ant new village July 15 answer
Online office, how to make collaboration more efficient?
Is it true that double non undergraduate students cannot enter the big factory? Ali technology four sides + cross face +hr face, successfully got the offer!!