当前位置:网站首页>贪心之区间问题(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;
}
};
边栏推荐
- 排序---
- [win11] right click fix to modify the registry but not create a new one
- 5G 短消息解决方案
- Mise en œuvre de redis par golang (10): transactions atomiques locales
- c# sqlsugar,hisql,freesql orm框架全方位性能测试对比之sqlserver
- Redis usage scenario sharing (project practice)
- Jenkins installation and upgrade
- 今天19:30 | 科普大佬说,带大家探寻AI如何激发人类的创造力
- Static linked list (I)
- The Fourth Youth Life Science Forum | first round notice
猜你喜欢
随机推荐
2022 G2 power plant boiler stoker question bank and online simulation examination
Jenkins configuration project integration pin notification
@Lucky user of "Qilu Duojiao", Shandong 5A scenic spot calls you to visit the park for free!
2022重庆幼教产业展览会|高科技玩具益智解压玩具博览会
2022焊工(初级)特种作业证考试题库模拟考试平台操作
Unity中通过射线躲避障碍物寻路的一些初步探索
sqlserver保存时遇到这个页面怎么回事啊
2022 operation of simulated examination platform for examination question bank of welder (elementary) special operation certificate
Niuke.com: consolidation interval
第四届青年生命科学论坛 | 第一轮通知
数组模拟栈
2022年R2移动式压力容器充装试题模拟考试平台操作
游戏NFT市场:OpenSea最易被切下的蛋糕
腾讯云国际版云服务器欠费说明
每天5分钟玩转Kubernetes | Dashboard典型使用场景
SystemVerilog (12) - $unit declaration space
wpa_cli参数说明
一些技术想法:
Filebeat收集日志数据传输到Redis,通过Logstash来根据日志字段创建不同的ES索引
Mysql如何删除数据库表中的某一列







