Intuition
Complexity
Runtime
Brute force: , where N is max_end - min_start, and M is the number of intervals.
Space
Code
Brute Force
class Solution:
def numberOfPoints(self, nums: List[List[int]]) -> int:
# For each point, if there is any car in that interval, then + 1. Otherwise, -1.
# Brute force: Just loop through each car for each point
min_start = min([num[0] for num in nums])
max_end = max(num[1] for num in nums)
res = 0
for i in range(min_start, max_end + 1):
for interval in nums:
# If there is at least one car which intersects
if i in range(interval[0], interval[1] + 1):
res += 1
break
return res