[LeetCode] 1805. Number of Different Integers in a String

Chobby·4일 전
1

LeetCode

목록 보기
608/650

😎풀이

  1. 숫자 문자열을 기준으로 그룹화
  2. BigInt로 형변환
  3. Set 자료구조에 입력으로 중복 제거
  4. 중복이 제거된 숫자 그룹의 수 조회
function numDifferentIntegers(word: string): number {
    const onlyNumStrs = word.match(/[0-9]+/g)
    if(!onlyNumStrs) return 0
    const transferToNum = onlyNumStrs.map(BigInt)
    const numSet = new Set([...transferToNum])
    return numSet.size
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글