1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
    int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
        int summ = 0;
        for(int i = 0; i < gas.size(); i++){
            summ += gas[i]-cost[i];
        }
        if(summ < 0return -1;
        
        int current = 0;
        int start = 0;
 
        for(int i = 0; i < gas.size(); i++){
            current += gas[i] - cost[i];
            if(current < 0){
                start = i+1;
                current = 0;
            }
        }
 
        return start;
    }
};
cs