leetcode: Gas Station
来源:互联网 发布:及时生成字幕软件 编辑:程序博客网 时间:2024/06/02 07:05
两重循环....
public class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { int gasNum = gas.length; if(gasNum<1) { return 0; } for(int i=0;i<gasNum;i++) { int gasAll = 0; int st=i; int end; if(st==0) { end = gasNum-1; int flag=0; for(int j=st;j<=end;j++) { gasAll += gas[j]-cost[j]; if(gasAll<0) { flag=1; break; } } if(flag==0) { return st; } } else { int flag=0; end = st-1; for(int j=st;j<=gasNum-1;j++) { gasAll += gas[j]-cost[j]; if(gasAll<0) { flag=1; break; } } for(int j=0;j<=st-1;j++) { gasAll += gas[j]-cost[j]; if(gasAll<0) { flag=1; break; } } if(flag==0) { return st; } } } return -1; }}
0 0
- LeetCode:Gas Station
- [LeetCode] Gas Station
- [leetcode]Gas Station
- Leetcode: Gas Station
- LeetCode:Gas Station
- [LeetCode] Gas Station
- leetcode Gas Station
- [LeetCode]Gas Station
- LeetCode 之 Gas Station
- leetcode Gas Station
- 【Leetcode】Gas Station
- LeetCode | Gas Station
- LeetCode之Gas Station
- Leetcode: Gas Station
- LeetCode OJ:Gas Station
- [LeetCode]134.Gas Station
- [Leetcode] Gas Station (Java)
- gas station leetcode
- 《C++ primer 5》 chapter 1.4
- ParaView整体介绍
- sersync2完全安装配置说明(一) —-基本功能使用
- Monkey Test 2(脚本方式)
- 邻居,你好!
- leetcode: Gas Station
- <<Oracle Applications DBA 基础(第二期)>>Week 10 exercise
- 黑马程序员 手写山寨版的金山词霸
- OCP 1Z0 053 147
- 字符串比较问题
- 插入排序
- JDOM操作XML实例
- MySQL-->基础知识-->mysql my.cnf 配置建议
- 数组中最出现一次的元素