mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 0135.分发糖果.md
Added python version code
This commit is contained in:
@ -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:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user