博客
关于我
134. Gas Station
阅读量:255 次
发布时间:2019-03-01

本文共 1276 字,大约阅读时间需要 4 分钟。

???????????????????????????????????????????????????????????????????????????????????????????????????

????

  • ????????????????????????????????????????????????-1?
  • ?????????????????????????????????????????????????????????????
  • ???????????????????????????????????????????
  • ????

    import java.util.Arrays;public class Solution {    public int canCompleteCircuit(int[] gas, int[] cost) {        int n = gas.length;        int sumGas = Arrays.stream(gas).sum();        int sumCost = Arrays.stream(cost).sum();                if (sumGas < sumCost) {            return -1;        }                for (int i = 0; i < n; i++) {            int current = gas[i];            boolean feasible = true;            for (int j = 0; j < n; j++) {                int next = (i + j) % n;                if (current < cost[next]) {                    feasible = false;                    break;                }                current -= cost[next];                current += gas[next];            }            if (feasible) {                return i;            }        }        return -1;    }}

    ????

  • ??????????????????????????????????????-1?
  • ?????????????????????????????????
  • ???????????????????????????????????????????????????
  • ???????????????????????????-1?
  • ????????????????????????????????????????????

    转载地址:http://pwxx.baihongyu.com/

    你可能感兴趣的文章
    PEP8规范
    查看>>
    PEPM Cookie 远程代码执行漏洞复现(XVE-2024-16919)
    查看>>
    Percona Server 5.6 安装TokuDB
    查看>>
    SpringBoot(十四)整合MyBatis
    查看>>
    percona-xtrabackup 备份
    查看>>
    Perfect,华为爆出 Redis 宝典,原来 Redis 性能可压榨到极致
    查看>>
    SpringBoot集成OpenOffice实现doc文档转html
    查看>>
    Perl Socket传输(带注释)
    查看>>
    ROS中机器人的强化学习路径规划器
    查看>>
    rocketmq存储结构_rocketmq 消息存储
    查看>>
    perl---2012学习笔记
    查看>>
    Perl6 必应抓取(1):测试版代码
    查看>>
    perl学习之内置变量
    查看>>
    perl正则表达式中的常用模式
    查看>>
    Perl的基本語法
    查看>>
    perl输出中文有乱码
    查看>>
    Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). 大数据ssh权限问题 hadoop起不来 hadoopssh错
    查看>>
    PermissionError:Python 中的 [Errno 13]
    查看>>
    PermissionError:[Errno 13] 权限被拒绝:‘/manage.py‘
    查看>>
    Permutation
    查看>>