[LeetCode] 448. Find All Numbers Disappeared in an Array

Chobby·2025년 4월 3일
1

LeetCode

목록 보기
327/427

😎풀이

  1. n: nums의 길이
  2. list: 0 ~ n 까지의 수
  3. nums 순회
    3-1. 현재 숫자 list에서 제거
  4. 제거되지 않은 숫자 중 0을 제외하고 반환
function findDisappearedNumbers(nums: number[]): number[] {
    const n = nums.length
    const list = Array(n + 1).fill(0).map((_, i) => i)
    for(const curNum of nums) {
        delete list[curNum]
    }
    return list.filter(a => a)
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글