Python
class Solution(object):
def canCompleteCircuit(self, gas, cost):
"""
:type gas: List[int]
:type cost: List[int]
:rtype: int
"""
sum_gas=0
sum_cost= 0
ans = 0
if(sum(gas)<sum(cost)):
return -1
for i in range(len(gas)):
sum_gas+=gas[i]
sum_cost+=cost[i]
if sum_gas<sum_cost:
sum_gas=0
sum_cost=0
ans=i+1
return ans