Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
- int n=gas.size(), total=0, start=0, curr=0;
- for(int i=0; i<n; i++){
- total += gas[i]-cost[i];
- curr += gas[i]-cost[i];
- if(curr< 0){
- start=i+1;
- curr=0;
- }
- }
- return total>=0 ? start:-1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement