class Solution {
public:
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
if (gas.empty() ||
cost.empty() ||
gas.size() != cost.size()){
return -1;
}
int size = gas.size();
for (int i = 0 ; i < size; i++) {
if (gas[i] - cost[i] >= 0) {
int start = i;
int val = 0, cnt = 0;
while (val >= 0) {
if (cnt == size) {
return i;
}
val += gas[start];
val -= cost[start];
start = (start + 1) % size;
cnt++;
}
}
}
return - 1;
}
};