[LeetCode] 3289. The Two Sneaky Numbers of Digitville

Chobby·2026년 1월 6일

LeetCode

목록 보기
887/992

😎풀이

  1. 두 개의 수를 제외한 모든 수는 고유함
  2. Set객체를 활용해 고유한 수 목록을 구성하며 중복될 경우 sneaky 배열에 추가
  3. 중복된 요소들로 이루어진 sneaky 배열 반환
function getSneakyNumbers(nums: number[]): number[] {
    const seen = new Set()
    const sneaky = []
    for(const num of nums) {
        if(seen.has(num)) sneaky.push(num)
        else seen.add(num)
    }
    return sneaky
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글