原题网址:https://leetcode.com/problems/best-meeting-point/
A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the group. The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.
For example, given three people living at

给定一个二维网格,其中1表示人的位置,目标是找到一个点,使得所有人到该点的曼哈顿距离之和最小。原题链接:https://leetcode.com/problems/best-meeting-point/。一维情况下,最佳点是坐标中位数,二维情况可分别求解水平和垂直的最佳点,然后组合。
最低0.47元/天 解锁文章
1079

被折叠的 条评论
为什么被折叠?



