题解 | 两点间距离

两点间距离

https://www.nowcoder.com/practice/94712d6f654143379f8ea5847d9d6225

import math
# class Point:
#     def __init__(self, a=0, b=0):
#         self.x = a
#         self.y = b
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 计算A点与B点之间的距离
# @param point_A Point类 A点
# @param point_B Point类 B点
# @return double浮点型
#
class Solution:
    def calculateDistance(self , point_A: Point, point_B: Point) -> float:
        # write code here
        x1,y1 = point_A.x,point_A.y
        x2,y2 = point_B.x,point_B.y
        distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
        return round(distance, 3)

全部评论

相关推荐

2025-12-27 22:21
门头沟学院 Java
点赞 评论 收藏
分享
2025-12-03 03:32
安徽大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务