首页 > 其他 > 详细

LeetCode 1503. 所有蚂蚁掉下来前的最后一刻

时间:2020-07-13 13:35:56      阅读:51      评论:0      收藏:0      [点我收藏+]

脑筋急转弯

每只蚂蚁都一样,相遇之后,相当于两人互换身份,继续朝原来的方向前进。因此,找出距离朝向端点最远的蚂蚁需要走多久,就是答案。

class Solution {
    public int getLastMoment(int n, int[] left, int[] right) {
        int res = -1;
        for(int i=0; i < left.length; i++)
            res = Math.max(res, left[i]);
        for(int i=0; i < right.length; i++)
            res = Math.max(res, n-right[i]);
        return res;
    }
}

LeetCode 1503. 所有蚂蚁掉下来前的最后一刻

原文:https://www.cnblogs.com/lixyuan/p/13292684.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!