[LeetCode] 929. Unique Email Addresses

Chobby·2025년 5월 22일
1

LeetCode

목록 보기
432/442

😎풀이

  1. Set 생성
  2. emails 순회
    2-1. localName은 다음 규칙을 따름
    2-2. .이 포함될 경우 무시
    2-3. +가 포함될 경우 이전 문자 까지만 인정
  3. 현재 이메일 Set에 추가
  4. Set 크기 반환환
function numUniqueEmails(emails: string[]): number {
    const emailSet = new Set<string>()
    for(const email of emails) {
        const [local, domain] = email.split('@')
        let realLocal = ''
        for(const char of local) {
            if(char === '.') continue
            if(char === '+') break
            realLocal += char
        }
        emailSet.add(realLocal + '@' + domain)
    }
    return emailSet.size
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글