Skip to content

Commit b0e3255

Browse files
committed
Runtime: 110 ms (Top 71.82%) | Memory: 69.4 MB (Top 89.07%)
1 parent cb74351 commit b0e3255

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
// Runtime: 110 ms (Top 71.82%) | Memory: 69.4 MB (Top 89.07%)
12
class Solution {
23
public:
34
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
45
int n = gas.size();
56
int start = -1;
6-
7+
78
int sum = 0 , gastillnow = 0;
89
for(int i = 0 ; i < 2*n ; i++){
910
if(start == i%n){
1011
return i%n;
1112
}
12-
if(gas[i%n] + gastillnow >= cost[i%n]){ // we can start from this index
13+
if(gas[i%n] + gastillnow >= cost[i%n]){ // we can start from this index
1314
if(start==-1) start = i;
1415
gastillnow += gas[i%n]-cost[i%n];
1516
}else if(gastillnow + gas[i%n] < cost[i%n]){ // previous start index was wrong we have to start from another
@@ -19,4 +20,4 @@ class Solution {
1920
}
2021
return -1;
2122
}
22-
};
23+
};

0 commit comments

Comments
 (0)