Merge pull request #138 from LiangDazhu/patch-8

添加 0135.分发糖果 python版本
This commit is contained in:
Carl Sun
2021-05-16 09:46:26 +08:00
committed by GitHub

View File

@ -161,7 +161,18 @@ class Solution {
```
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