当前位置:网站首页>LeetCode 135. 分发糖果
LeetCode 135. 分发糖果
2022-08-04 06:42:00 【HumbleFool】

贪心
class Solution {
public:
int candy(vector<int>& ratings) {
int n = ratings.size();
vector<int> left(n, 1);
vector<int> right(n, 1);
for(int i = 1; i < n; i ++)
if(ratings[i] > ratings[i - 1])
left[i] += left[i - 1];
for(int i = n - 2; i >= 0; i --)
if(ratings[i] > ratings[i + 1])
right[i] += right[i + 1];
int res = 0;
for(int i = 0; i < n; i ++)
res += max(left[i], right[i]);
return res;
}
};
边栏推荐
- Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
- Detailed ResNet: What problem is ResNet solving?
- 误差指标分析计算之matlab实现【开源1.0.0版】
- Amazon亚马逊 Vendor Central Label详解
- 分布式计算实验3 基于PRC的书籍信息管理系统
- Distributed Computing Experiment 2 Thread Pool
- ConstraintSet of animation of ContrstrainLayout
- 两日总结四
- 科研绘图图表类型种类繁多,本文告诉你如何选择!
- matlab让我的旧手机起死回生
猜你喜欢
随机推荐
系统流量预估、架构设计方案
【愚公系列】2022年07月 Go教学课程 027-深拷贝和浅拷贝
likeshop单商户高级版企业源码发布了新的版本1.8.1
经典新诗九首
C语言实现-华为太空人手表
ConstraintSet of animation of ContrstrainLayout
MMDeploy部署实战系列【第四章】:onnx,tensorrt模型推理
用手机也能轻松玩转MATLAB编程
Produce definition 产品与行业分析 勤于思考 善于总结 强于表达
MySQL重置root密码
LeetCode每日五题01:两数之和 (均1200题)
关于我写的循环遍历
Centos通过Docker搭建MySQL的PXC集群
无人驾驶运用了什么技术,无人驾驶技术是
LAN技术-3iStack
经典宋诗排行榜
舍不得花钱买1stOpt,不妨试试这款免费的拟合优化神器【openLU】
TCP协议详解
【学习笔记】AGC036
unity webgl报 Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON







![[想要访问若依后台]若依框架报错401请求访问:error认证失败,无法访问系统资源](/img/aa/701fef9d8d7eaf25082e1289799b77.png)

