[LeetCode] 2540. Minimum Common Value

Chobby·2025년 11월 13일

LeetCode

목록 보기
755/826

😎풀이

  1. nums 순회
    1-1. 교집합 확인
    1-2. 교집합 중 최소 값 반환
  2. 존재하지 않다면 -1 반환
function getCommon(nums1: number[], nums2: number[]): number {
    const set1 = new Set(nums1)
    const set2 = new Set(nums2)
    for(const num of set1) {
        if(!set2.has(num)) continue
        return num
    }
    return -1
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글