#2848
Points That Intersect With Cars
newbie · 255 · lc easy +19 · verified · 73.4% accepted · 370 likes · top 84%
Description
A 0-indexed 2D integer array nums represents cars parked on a number line. For each i, nums[i] = [starti, endi] gives the start and end positions of the i-th car.
Return the number of integer points on the number line covered by at least one car.
Example 1:
Input: nums = [[3,6],[1,5],[4,7]]
Output: 7
Explanation: All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.
Example 2:
Input: nums = [[1,3],[5,8]]
Output: 7
Explanation: Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.
Code
1
2
3