Skip to content

[WEEK06-2] 추슬기#25

Open
doitchuu wants to merge 2 commits intopnt-fe-study:mainfrom
doitchuu:doitchuu
Open

[WEEK06-2] 추슬기#25
doitchuu wants to merge 2 commits intopnt-fe-study:mainfrom
doitchuu:doitchuu

Conversation

@doitchuu
Copy link
Member

이렇게 풀었어요

1. Contains Duplicate

  • 문제를 풀었어요.
  • 풀이 시간 : 1분

1) 복잡도 계산

  • 시간 복잡도: O(n)
  • 공간 복잡도: O(n)

2) 접근 아이디어

  1. 배열 길이와 Set으로 중복 제거한 뒤의 길이를 비교했다.
  2. 길이가 다르면 중복이 존재한다고 판단했다.
  3. 비교 결과를 그대로 boolean 값으로 반환했다.

3) 회고

Set(nums)로 바로 길이를 비교하는 방식이라 구현은 빠르고 간단했다.

다른 사람 풀이:

/**
 * @param {number[]} nums
 * @return {boolean}
 */
var containsDuplicate = function(nums) {
    let set = new Set();
    for(let item of nums){
        if(set.has(item)) return true;
        set.add(item);
    }
    return false;
};

다른 사람 풀이 핵심: 값을 하나씩 보면서 이미 본 값인지 바로 확인하고, 중복이 발견되는 순간 즉시 종료하는 방식이었다.
내 생각: Set으로 값을 하나씩 저장하고 같은 값이 나오면 바로 boolean 값을 반환하는 방식이 더 빠를 수 있겠다고 느꼈다.



2. Roman to Integer

  • 문제를 풀었어요.
  • 풀이 시간 : 22분

1) 복잡도 계산

  • 시간 복잡도: O(n)
  • 공간 복잡도: O(1)

2) 접근 아이디어

  1. 로마 숫자와 정수를 매핑한 객체를 먼저 만들었다.
  2. 현재 문자와 다음 문자를 비교해서 현재 값이 더 작으면 빼고, 아니면 더했다.
  3. 마지막 문자는 비교 대상이 없으니 반복문이 끝난 뒤 따로 더해 최종 합을 구했다.

3) 회고

현재 문자와 다음 문자를 비교해서 더할지 뺄지를 결정하는 흐름으로 정리하니 문제 구조가 훨씬 잘 보였다.

처음엔 if문을 길게 써서 문자마다 값을 바로 반환하는 방식도 생각했다.

if(letter === 'I') return 1;
if(letter === 'V') return 5;
if(letter === 'X') return 10;
if(letter === 'L') return 50;
if(letter === 'C') return 100;
if(letter === 'D') return 500;
if(letter === 'M') return 1000;

이런 식으로 미리 early return을 줘도 괜찮을 것 같긴 한데, 이번에는 객체로 매핑해 두는 쪽이 반복 계산할 때 더 깔끔하게 느껴졌다.



@doitchuu doitchuu requested review from raejun92 and sik9252 March 18, 2026 12:18
@doitchuu doitchuu self-assigned this Mar 18, 2026
Copy link
Collaborator

@raejun92 raejun92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

const arrLength = nums.length;
const set = new Set(nums);

return arrLength !== set.size;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 길이 비교는 생각을 못했네요

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저랑 풀이가 똑같네요!ㅎ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants