Leetcode # 2848. Points That Intersect With Cars
- 2023.09.10
- ★ Easy LeetCode Merge Intervals
Problem
https://leetcode.com/contest/weekly-contest-362/problems/points-that-intersect-with-cars/
相關例題
Solution
Time Complexity: O(len(nums))
Space Complexity: O(1)
(The input and output generally do not count towards the space complexity.)
class Solution:
def numberOfPoints(self, nums: List[List[int]]) -> int:
nums.sort()
n = len(nums)
start, end = nums[0]
points = 0
for i, num in enumerate(nums[1:], 1):
if num[0] <= end:
end = max(num[1], end)
else:
points += end - start + 1
start, end = num
points += end - start + 1
return points
Last Updated on 2023/09/10 by A1go