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

    你可能感兴趣的文章
    PHP mongoDB 操作
    查看>>
    ReentrantLock读写锁
    查看>>
    ReentrantLock的公平锁与非公平锁
    查看>>
    php mysql procedure获取多个结果集
    查看>>
    php mysql query 行数,PHP和MySQL:返回的行数
    查看>>
    php mysql session_php使用MySQL保存session会话
    查看>>
    PHP mysql_real_escape_string() 函数防SQL注入
    查看>>
    php mysql优化方法_MySQL优化常用方法
    查看>>
    PHP OAuth 2.0 Server
    查看>>
    php odbc驱动,php常用ODBC函数集(详细)
    查看>>
    php openssl aes ecb,php openssl_encrypt AES-128-ECB iOS
    查看>>
    php paypal rest api,PayPal REST API指定网络配置文件PHP
    查看>>
    php pcntl 多进程学习
    查看>>
    PHP pcntl_fork不能在web服务器中使用的变通方法
    查看>>
    php private ,public protected三者的区别
    查看>>
    php PSR规范
    查看>>
    php rand() 重复,array_rand()函数从另外一个数组中随机取得的一定数量的数组的元素是否会重复?...
    查看>>
    php redis pub/sub(Publish/Subscribe,发布/订阅的信息系统)之基本使用
    查看>>
    php redis 集群扩展类文件
    查看>>
    php redis(2)
    查看>>