2025-09-02 17:18:23 +0000 UTC
Find the Number of Ways to Place People I
Categories:
Links
Code
class Solution:
def numberOfPairs(self, points: List[List[int]]) -> int:
ans = 0
n = len(points)
for i in range(n):
pointA = points[i]
for j in range(n):
pointB = points[j]
if i == j or not (
pointA[0] <= pointB[0] and pointA[1] >= pointB[1]
):
continue
if n == 2:
ans += 1
continue
illegal = False
for k in range(n):
if k == i or k == j:
continue
pointTmp = points[k]
isXContained = (
pointTmp[0] >= pointA[0] and pointTmp[0] <= pointB[0]
)
isYContained = (
pointTmp[1] <= pointA[1] and pointTmp[1] >= pointB[1]
)
if isXContained and isYContained:
illegal = True
break
if not illegal:
ans += 1
return ans