题解 | #最大差值#

最大差值

http://www.nowcoder.com/practice/1f7675ae7a9e40e4bd04eb754b62fd00

temp记录最小值,res记录数组元素与temp之间差值的最大值

import java.util.*;

public class LongestDistance {
    public int getDis(int[] A, int n) {
        // write code here
        if(A==null ||A.length<2) return 0;
        int res=0,temp=A[0];
        for(int i=1;i<A.length;i++){
            temp=Math.min(temp,A[i]);
            res=Math.max(res,A[i]-temp);
        }
        return res;

    }
}
全部评论

相关推荐

刘湘_passion:太强了牛肉哥有被激励到
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务