标签:
1. ArrayGasStation
题很简单,就是比较两个Array
package LeeCodeCrack; public class ArrayGasStation { public int Circuit(int[] gas,int[]cost){ int sum=0; int index=0; int x=0; for(int i=0;i<gas.length;i++){ sum+=gas[i]-cost[i]; if(sum<0){ index=i; }else{ index=-1; } } return index; } public static void main(String[] args){ ArrayGasStation a=new ArrayGasStation(); int[] gas={1,2,3,3}; int[] cost={1,2,3,4}; int result=a.Circuit(gas, cost); System.out.println(result); } }
标签:
原文地址:http://www.cnblogs.com/ChrisY/p/5448054.html