leetcode-5361-圆和矩形是否有重叠
Posted 真不知道叫啥好
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode-5361-圆和矩形是否有重叠相关的知识,希望对你有一定的参考价值。
题目描述:
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-圆和矩形是否有重叠的主要内容,如果未能解决你的问题,请参考以下文章