[leetcode] 317. Shortest Distance from All Buildings 解题报告

本文介绍了LeetCode上的第317题,题目要求找到一片空地,使得从这片空地到所有建筑物的距离之和最小。不能通过值为1的建筑物和值为2的障碍物。通过从一个建筑物出发使用BFS算法计算每个空地到所有建筑物的距离,若无法找到合适的位置则返回-1。文章提供了详细的解题思路和代码实现。
摘要由CSDN通过智能技术生成

题目链接: https://leetcode.com/problems/shortest-distance-from-all-buildings/

You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. You are given a 2D grid of values 01 or 2, where:

  • Each 0 marks an empty land which you can pass by freely.
  • Each 1 marks a building which you cannot pass through.
  • E
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值