雷达检测

http://www.lintcode.com/zh-cn/problem/radar-detection/

/**
 * Definition for a point.
 * class Point {
 *     int x;
 *     int y;
 *     Point() { x = 0; y = 0; }
 *     Point(int a, int b) { x = a; y = b; }
 * }
 */

public class Solution {
    /**
     * @param coordinates: The radars' coordinate
     * @param radius: Detection radius of radars
     * @return: The car was detected or not
     */
    public String radarDetection(Point[] coordinates, int[] radius) {
        // Write your code here
        //计算每个雷达的坐标到x轴的距离,要大于radius,
        for (int i = 0; i < coordinates.length; i++) {
            Point coordinate = coordinates[i];
            if(Math.abs(coordinate.y)<=radius[i]){
                return "YES";
            }
        }
        return "NO";
    }
}

你可能感兴趣的:(雷达检测)