1779. 找到最近的有相同 X 或 Y 坐标的点

1779. 找到最近的有相同 X 或 Y 坐标的点

class Solution {
    public int nearestValidPoint(int x, int y, int[][] points) {
        int n = points.length;
        int res = (int)0x3f3f3f3f;
        int index = -1;
        for(int i = 0; i < n; i ++) {
            int x1 = points[i][0], y1 = points[i][1];
            if(x1 == x || y1 == y) {
                int dis = Math.abs(x - x1) + Math.abs(y - y1);
                if(res > dis) {
                    index = i;
                    res = dis;
                }
                
            }
        }
        return index;
    }
}
posted @   Eiffelzero  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
点击右上角即可分享
微信分享提示