mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 12:15:58 +08:00
@ -161,7 +161,18 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def candy(self, ratings: List[int]) -> int:
|
||||||
|
candyVec = [1] * len(ratings)
|
||||||
|
for i in range(1, len(ratings)):
|
||||||
|
if ratings[i] > ratings[i - 1]:
|
||||||
|
candyVec[i] = candyVec[i - 1] + 1
|
||||||
|
for j in range(len(ratings) - 2, -1, -1):
|
||||||
|
if ratings[j] > ratings[j + 1]:
|
||||||
|
candyVec[j] = max(candyVec[j], candyVec[j + 1] + 1)
|
||||||
|
return sum(candyVec)
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
@ -172,4 +183,4 @@ Go:
|
|||||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
||||||
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
|
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
|
||||||
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
|
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
|
||||||
|
Reference in New Issue
Block a user