Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c language

int can(int[] gas, int[] cost) {
        begin = 0
        sum = 0
        tank = 0
        for( i = 0 to i < gas.size() ) {
            tank = tank + gas[i] - cost[i]
            if(tank < 0) {
                begin = i+1
                sum= sum + tank
                tank=0
            }
        }
        if(sum + tank < 0) {
            return -1
        } else { 
            return start
        }
    }
Source by afteracademy.com #
 
PREVIOUS NEXT
Tagged: #language
ADD COMMENT
Topic
Name
8+7 =