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
commit ba8bf3ac20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -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