当前位置:网站首页>贪心之区间问题(2)
贪心之区间问题(2)
2022-06-22 17:50:00 【Douglas_LT】
每日一题ing,今天是个easy题力扣605. Can Place Flowers
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
int init=0,sum=0;
flowerbed.push_back(0);//右边界不用考虑
for(int i=0;i<flowerbed.size();i++)
{
if(flowerbed[i]==1)
init++;
}
if(flowerbed[1]==0)
flowerbed[0]=1;
for(int i=1;i<flowerbed.size()-1;i++)
{
if(flowerbed[i-1]!=1&&flowerbed[i+1]!=1)
flowerbed[i]=1;
}
for(int i=0;i<flowerbed.size();i++)
{
if(flowerbed[i]==1)
sum++;
}
if(sum-init>=n)
return true;
return false;
}
};
边栏推荐
- Notes on new reports
- Concepts and solutions of redis' cache penetration, cache avalanche and cache breakdown problems
- Unity中通过射线躲避障碍物寻路的一些初步探索
- PostgreSQL reconfigure from library
- Jenkins configuration project integration pin notification
- Some preliminary explorations of avoiding obstacles and finding paths by rays in unity
- How much do you know about the bloom filter and cuckoo filter in redis?
- How to manage tasks in note taking software such as flowus and notation?
- Golang实现基于Redis的可靠延迟队列
- How can I automatically make an appointment to make a new debt? Is it convenient and safe to make an appointment to make a new bond
猜你喜欢

< JVM part I: memory and garbage collection part > 08 object instantiation and direct memory

Unity中通过射线躲避障碍物寻路的一些初步探索
Golang implements reliable delay queue based on redis

腾讯云国际版云服务器欠费说明

STM32控制矩阵按键,HAL库,cubeMX配置

Postman learning
Set of redis data structure

RSPS2022 Finalist | Dr. Yang Bai 简介

3GPP 5G R17标准冻结,RedCap作为重要特性值得关注!

巴比特 | 元宇宙每日必读:传腾讯成立XR部门,元宇宙板块再次上涨,多家券商发报告关注虚拟人的投资机会...
随机推荐
排序---
PLSQL variable assignment
std::enable_ shared_ from_ This error: error: expected template name before '<' token
JVM quick start
5GC和卫星融合通信方案
SRE必将走向混沌工程时代--华为云混沌工程实践
零基础学编程/学逆向/过检测(frida实战)
Makefile将某一部分文件不编译
You guys, the first time you used flick MySQL CDC, now the program starts without error, and the new data is not printed out
2022 Chongqing preschool education industry exhibition 𞓜 hi tech Toy Puzzle decompression Toy Expo
Set of redis data structure
Which securities company is better to open an account when making an appointment to play new bonds? It is safer to open an account
plsql变量赋值问题
Grafana 9 is officially released, which is easier to use and more cool!
3GPP 5G R17标准冻结,RedCap作为重要特性值得关注!
c# sqlsugar,hisql,freesql orm框架全方位性能测试对比之sqlserver
What is the experience of writing a best seller
Five practical tips for power Bi (complimentary books at the end of the article)
Cookie加密3+RPC解法
2022 G2 power plant boiler stoker question bank and online simulation examination