Fork me on GitHub

牛客网2016校招真题在线编程之最大差值

 

直接暴力搜即可。

 

AC代码:

import java.util.*;

public class LongestDistance {
    
    public int getDis(int[] A, int n) {
        int res = Integer.MIN_VALUE;
        for(int i=0; i<A.length-1; i++){
            for(int j=i+1; j<A.length; j++){
                res = Math.max(A[j]-A[i], res);
            }
        }
        return res;
    }
    
}

  

题目来源: https://www.nowcoder.com/practice/1f7675ae7a9e40e4bd04eb754b62fd00?tpId=49&tqId=29281&tPage=1&rp=1&ru=/ta/2016test&qru=/ta/2016test/question-ranking

posted @ 2017-11-26 02:28  CC11001100  阅读(251)  评论(0编辑  收藏  举报