博客
关于我
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/

    你可能感兴趣的文章
    R&Python Data Science 系列:数据处理(4)长宽格式数据转换
    查看>>
    PHP项目集成支付宝PC端扫码支付API(国内支付)
    查看>>
    php预定义常量&变量
    查看>>
    R 集成算法③ 随机森林
    查看>>
    php验证码背景色设置无效
    查看>>
    php验证邮箱是否有效
    查看>>
    PHP高性能分布式应用服务器框架-SwooleDistributed
    查看>>
    PHP高效、轻量级表格数据处理库 OpenSpout
    查看>>
    R 数据缺失的处理
    查看>>
    php,nginx重启
    查看>>
    php:$_ENV 和 getenv区别
    查看>>
    PHP:cURL error 60: SSL certificate unable to get local issuer certificate
    查看>>
    PHP:PDOStatement::bindValue参数类型php5和php7问题
    查看>>
    Q媒体播放器.如何播放具有多个音频的视频?
    查看>>
    pickle
    查看>>
    Pickle thread.lock(Pymongo)
    查看>>
    pickle模块
    查看>>
    qYKVEtqdDg
    查看>>
    pid控制
    查看>>
    PID控制介绍-ChatGPT4o作答
    查看>>