当前位置:网站首页>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;
}
};
边栏推荐
- 中职网络安全竞赛C模块MS17-010批量扫描
- LLVM编译技术应用分析
- 核心价值观编码器【matlab版】
- ConstraintSet of animation of ContrstrainLayout
- 有人试过用NPGsql驱动连接openGauss开发应用的吗?
- 零分贝超静音无线鼠标!数量有限!!先到先得!!!【元旦专享】
- 错误记录:TypeError: object() takes no parameters
- ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
- 对产品设计,架构设计的一点思考
- JVM调优实践
猜你喜欢

curl (7) Failed connect to localhost8080; Connection refused

data:image/jpg;base64格式数据转化为图片

2022年7月总结

窥探晶体世界的奥秘 —— 230种空间群晶体结构模型全在这里

FCN - the originator of semantic segmentation (based on tf-Kersa reproduction code)
![[Paper Notes] - Low Illumination Image Enhancement - Supervised - RetinexNet - 2018-BMVC](/img/54/685fb2620aa53416437943705d3d38.png)
[Paper Notes] - Low Illumination Image Enhancement - Supervised - RetinexNet - 2018-BMVC

舍不得花钱买1stOpt,不妨试试这款免费的拟合优化神器【openLU】

【愚公系列】2022年07月 Go教学课程 027-深拷贝和浅拷贝

10个程序员可以接私活的平台和一些建议,赚麻...
![(19)[系统调用]SSTD hook 阻止关闭](/img/73/e9d591af366db17965d0bf1cf192b7.png)
(19)[系统调用]SSTD hook 阻止关闭
随机推荐
LeetCode每日五题01:两数之和 (均1200题)
LAN技术-3iStack
指定区域内随机填充圆之matlab实现
【论文笔记】—低照度图像增强—Supervised—RetinexNet—2018-BMVC
函数柯里化详解
pycharm专业版使用
ExoPlayer添加Ffmpeg扩展实现软解功能
JVM工具之 JPS
Activiti 工作流引擎 详解
将回调函数转为Flow
likeshop单商户高级版企业源码发布了新的版本1.8.1
有趣的USB接口和颜色分类
Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
adb无法桥接夜神模拟器
核心价值观编码器【matlab版】
Detailed ResNet: What problem is ResNet solving?
有人试过用NPGsql驱动连接openGauss开发应用的吗?
详解CAN总线:常用CAN连接器的使用方法
Mac安装PHP开发环境
专题讲座7 计算几何 学习心得