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.
1 parent 7b3f8ea commit 045f3f9Copy full SHA for 045f3f9
problems/0134.加油站.md
@@ -241,7 +241,28 @@ class Solution:
241
242
Go:
243
244
+Javascript:
245
+```Javascript
246
+var canCompleteCircuit = function(gas, cost) {
247
+ const gasLen = gas.length
248
+ let start = 0
249
+ let curSum = 0
250
+ let totalSum = 0
251
+
252
+ for(let i = 0; i < gasLen; i++) {
253
+ curSum += gas[i] - cost[i]
254
+ totalSum += gas[i] - cost[i]
255
+ if(curSum < 0) {
256
+ curSum = 0
257
+ start = i + 1
258
+ }
259
260
261
+ if(totalSum < 0) return -1
262
263
+ return start
264
+};
265
+```
266
267
268
-----------------------
0 commit comments