当前位置:网站首页>贪心之区间问题(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;
}
};
边栏推荐
- 预训练语言模型,bert,RoFormer-Sim又称SimBERTv2
- 排序---
- Concepts and solutions of redis' cache penetration, cache avalanche and cache breakdown problems
- [learn shell programming easily]-4. The difference between single quotation marks and double quotation marks, the operation of integer values, the definition of arrays in the shell and the detailed us
- Interview MySQL
- Unity中通过射线躲避障碍物寻路的一些初步探索
- Niuke.com: consolidation interval
- Several important viewpoints on operation and maintenance, monitoring and aiops
- [tools] related use of PIP and CONDA
- ADAU1452开发系统界面与代码数据之间的关系
猜你喜欢
随机推荐
Oracle中dbms_output.put_line的用法实例
中国两颗风云气象“新星”数据产品向全球用户共享
[OWT] OWT client native P2P E2E test vs2017 build
chrome突然无法复制粘贴了
Cookie encryption 3+rpc solution
2022焊工(初级)特种作业证考试题库模拟考试平台操作
每天5分钟玩转Kubernetes | Dashboard典型使用场景
PLSQL variable assignment
Notes on new reports
Babbitt | yuancosmos daily must read: it is said that Tencent has established XR department, and yuancosmos sector has risen again. Many securities companies have issued reports to pay attention to th
如何提高工作效率?苹果电脑效率工具合集
Makefile将某一部分文件不编译
ADAU1452开发系统界面与代码数据之间的关系
Golang 實現 Redis(10): 本地原子性事務
Robotframework installation tutorial
sqlserver保存时遇到这个页面怎么回事啊
Game NFT Market: opensea's most easily cut cake
In May, 2022, China's game manufacturers and applications went to sea, with top 30 revenue in EMEA region
今天19:30 | 科普大佬说,带大家探寻AI如何激发人类的创造力
Traditional image -- LBP feature








