134.Gas Station

Source: Internet
Author: User

    /** 134.Gas Station * 2016-5-22 by Mingyang * At the beginning of their own time, a point of the calculation, time more than * here once, each time from a I, regardless of total income should be greater than the total Expenses, or no matter how the turn is not good * In addition, once every walk is not moving, the starting point jumps to the next I*/     Public intCancompletecircuit (int[] Gas,int[] cost) {        if(gas==NULL|| cost==NULL|| gas.length==0| | cost.length==0| | gas.length!=cost.length)return-1; intsum = 0; intTotal = 0; intindex = 0;  for(inti = 0; i < gas.length; i++) {sum+ = gas[i]-Cost[i]; Total+ = gas[i]-Cost[i]; if(Sum < 0) {Index=i+1; Sum= 0; }         }          if(total<0)            return-1; Else            returnindex; }

134.Gas Station

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.