[LeetCode] 2848. Points That Intersect With Cars

Chobby·4일 전

LeetCode

목록 보기
807/826

😎풀이

  1. nums 순회
    1-1. 각 주차된 차량의 시작점 부터 끝점까지 순회
    1-2. 각 점의 좌표를 추가
  2. 중복 제거된 모든 점의 좌표 크기를 반환
function numberOfPoints(nums: number[][]): number {
    const points = new Set()
    for(const [start, end] of nums) {
        for(let i = start; i <= end; i++) {
            points.add(i)
        }
    }
    return points.size
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글