题解 | 两点间距离
两点间距离
https://www.nowcoder.com/practice/94712d6f654143379f8ea5847d9d6225
题干解读:给出两个点数据,要求他们之间的举例
解题思路:直接使用点到点之间的举例公式即可.
/**
* struct Point {
* int x;
* int y;
* Point(int xx, int yy) : x(xx), y(yy) {}
* };
*/
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 计算A点与B点之间的距离
* @param point_A Point类 A点
* @param point_B Point类 B点
* @return double浮点型
*/
double calculateDistance(Point point_A, Point point_B) {
double dis;
dis = sqrt((point_A.x-point_B.x)*(point_A.x-point_B.x)+(point_A.y-point_B.y)*(point_A.y-point_B.y));
return dis;
}
};

字节跳动公司福利 1371人发布