Skip to content

Commit ba8bf3a

Browse files
Merge pull request youngyangyang04#138 from LiangDazhu/patch-8
添加 0135.分发糖果 python版本
2 parents e8b4c80 + 69b766e commit ba8bf3a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

problems/0135.分发糖果.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,18 @@ class Solution {
161161
```
162162

163163
Python:
164-
164+
```python
165+
class Solution:
166+
def candy(self, ratings: List[int]) -> int:
167+
candyVec = [1] * len(ratings)
168+
for i in range(1, len(ratings)):
169+
if ratings[i] > ratings[i - 1]:
170+
candyVec[i] = candyVec[i - 1] + 1
171+
for j in range(len(ratings) - 2, -1, -1):
172+
if ratings[j] > ratings[j + 1]:
173+
candyVec[j] = max(candyVec[j], candyVec[j + 1] + 1)
174+
return sum(candyVec)
175+
```
165176

166177
Go:
167178

@@ -172,4 +183,4 @@ Go:
172183
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
173184
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
174185
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
175-
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
186+
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>

0 commit comments

Comments
 (0)