leetcode - Candy
来源:互联网 发布:java按键监听器 编辑:程序博客网 时间:2024/06/10 01:16
class Solution {public: int candy(std::vector<int> &ratings) {std::vector<int> ans(ratings.size(),0);ans[0] = 1;int sz = ratings.size();for (int i = 1; i < sz; i++){if(ratings[i-1] < ratings[i]){ans[i] = ans[i-1] + 1;}else{ans[i] = 1;}}for(int i = sz - 2; i >= 0; i--){if(ratings[i+1] < ratings[i]){int t = ans[i+1] + 1;ans[i] = t > ans[i] ? t : ans[i];}}int s = 0;for (int i = 0; i < sz; i++){s += ans[i];}return s; }};
0 0
- Leetcode: Candy
- LeetCode:Candy
- [leetcode]Candy
- Leetcode: Candy
- 【leetcode】Candy
- LeetCode:Candy
- [LeetCode] Candy
- [LeetCode]Candy
- [LeetCode] Candy
- 【LeetCode】Candy
- LeetCode | Candy
- Leetcode: Candy
- Candy - LeetCode
- leetcode Candy
- LeetCode Candy
- candy leetcode
- Candy -- LeetCode
- [LeetCode] Candy
- hda and hdb
- ubuntu 终端下快捷键
- OpenMP实现生产者消费者模型
- Hdu 4111 Alice and Bob(博弈+记忆化搜索)
- Codeforces Round #261 (Div. 2) C. Pashmak and Buses
- leetcode - Candy
- USB端口数据分析
- nextLine()和next()的区别和使用方法
- 怎样在Word中插入代码并保持样式不变
- 获取JAVA文件路径
- HDU 3371 Connect the Cities
- struts与spring整合的原理
- Java实现快速排序
- 大型网站架构