We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 34db204 + 10a2089 commit 49788abCopy full SHA for 49788ab
problems/0135.分发糖果.md
@@ -176,7 +176,30 @@ class Solution:
176
177
Go:
178
179
+Javascript:
180
+```Javascript
181
+var candy = function(ratings) {
182
+ let candys = new Array(ratings.length).fill(1)
183
+
184
+ for(let i = 1; i < ratings.length; i++) {
185
+ if(ratings[i] > ratings[i - 1]) {
186
+ candys[i] = candys[i - 1] + 1
187
+ }
188
189
190
+ for(let i = ratings.length - 2; i >= 0; i--) {
191
+ if(ratings[i] > ratings[i + 1]) {
192
+ candys[i] = Math.max(candys[i], candys[i + 1] + 1)
193
194
195
196
+ let count = candys.reduce((a, b) => {
197
+ return a + b
198
+ })
199
200
+ return count
201
+};
202
+```
203
204
205
-----------------------
0 commit comments