腾讯2019笔试第5题

/**
 * @program tencert2019——5
 * @description: demo
 * @author: payne
 * @create: 2019/03/10 21:47
 */
import java.util.*;
import java.util.Arrays;
public class main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i=0;i map = new HashMap();
            for (int j=i-1;j>=0;j--){
                int value= a[j]-a[i];
                if (value<=0) {
                    value = -1*value;
                }
                map.put(value,j);
            }

            Object[] key =  map.keySet().toArray();
            Arrays.sort(key);

            int key1 = (int)key[0];
            int index = map.get(key1);
            res[i-1][0] = key1;
            res[i-1][1] = index+1;
        }
        return res;
    }
}


第2题和第4题哪个大神会做 求教啊~

你可能感兴趣的:(笔试记录)