算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !
今天和大家聊的问题叫做 平面上的最近距离,我们先来看题面:
https://leetcode.cn/problems/shortest-distance-in-a-plane/
解题
会计算点点之间的距离便可
筛选条间注意要去掉本身与本身求距离,也能够使用(p1.x,p1.y) != (p2.x,p2.y)
# Write your MySQL query statement below
select round(min(sqrt(power(p1.x-p2.x, 2)+power(p1.y-p2.y, 2))), 2) shortest
from point_2d p1, point_2d p2
where p1.x < p2.x or (p1.x = p2.x and p1.y != p2.y)
上期推文:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有