算法 - 排序数组中与x最近一点

 

条件:

a[j] + a[j+1] < x*2

 

int findClosestPoint(int x,int a [])
{
    int res = 0;
    int j = 0;
    while(j<a.length-1 && a[j]+a[j+1]<x*2) j++;
    res = Math.max(res,Math.abs(x-a[j]));
    return res;
}

 

posted @ 2017-10-27 16:36  qlky  阅读(255)  评论(0编辑  收藏  举报