码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode-5361-圆和矩形是否有重叠

时间:2020-04-05 11:27:27      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:bsp   return   leetcode   lse   radius   als   info   self   矩形   

题目描述:

技术图片

 

 

class Solution:
    def checkOverlap(self, radius: int, x_center: int, y_center: int, x1: int, y1: int, x2: int, y2: int) -> bool:
        a = max(0, x1 - x_center, x_center - x2) ** 2 
        b = max(0, y1 - y_center, y_center - y2) ** 2
        c = radius ** 2
        return a + b <= c

class Solution:
    def checkOverlap(self, radius: int, x_center: int, y_center: int, x1: int, y1: int, x2: int, y2: int) -> bool:
        for x in (x1, x2):
            for y in (y1, y2):
                if dist((x_center, y_center), (x, y)) <= radius:
                    return True
        if x1 <= x_center <= x2 and y1 - radius  <= y_center <= y2 + radius:
            return True
        if x1 - radius <= x_center <= x2 + radius and y1  <= y_center <= y2:
            return True
        return False

 

leetcode-5361-圆和矩形是否有重叠

标签:bsp   return   leetcode   lse   radius   als   info   self   矩形   

原文地址:https://www.cnblogs.com/oldby/p/12636086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!