Skip to content

[WEEK06-2] 이지현#27

Merged
sik9252 merged 2 commits into
mainfrom
sik9252
Mar 22, 2026
Merged

[WEEK06-2] 이지현#27
sik9252 merged 2 commits into
mainfrom
sik9252

Conversation

@sik9252
Copy link
Copy Markdown
Collaborator

@sik9252 sik9252 commented Mar 19, 2026

이렇게 풀었어요

1. Contains Duplicate

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

1) 복잡도 계산

시간 복잡도: O(n)

공간 복잡도: O(n)


2) 접근 아이디어

중복이란 키워드를 보고 바로 Set이 떠올랐고, 원본 길이와 Set 길이를 비교해서 다르면 중복이 있다는 것을 알 수 있다.


3) 회고

다른 방법으로는 배열을 정렬한 뒤 인접한 원소끼리 비교하는 방법이 있을 것 같다.
하지만 이 방법은 시간 복잡도가 O(n log n)이 되므로 Set을 이용하는 방법이 더 효율적이다. (그러나 공간복잡도는 이 방법이 더 효율적일듯 o(log n)정도.)


2. Roman to Integer

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

1) 복잡도 계산

시간 복잡도: O(n)

공간 복잡도: O(1)


2) 접근 아이디어

로마 숫자는 기본적으로 왼쪽에서 오른쪽으로 더하면 되지만, 현재 문자가 다음 문자보다 작은 경우는 빼주는 규칙이 있다.
따라서 각 문자를 순회하면서 다음 문자와 비교해 작으면 빼고, 아니면 더하는 방식으로 구현했다.


3) 회고

처음에는 단순히 문자마다 값을 더하는 문제라고 생각했는데, 실제로는 다음 문자와의 관계를 봐야 한다는 점이 중요했다.
예외 케이스를 따로 외워서 처리하기보다, 현재 값과 다음 값을 비교하는 규칙으로 풀 수 있다는 점이 인상적이었다.

Copy link
Copy Markdown
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.

고생하셨습니다. 이번엔 그렇게 어렵지 않아서 금방 푸셧네요!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

슬기님 풀이와 같군요!
Set에 모든 배열을 넣지않고 하나씩 확인하면서 얼리 리턴을 하면 조금 더 빠를 수 있을 것 같아요

seulgichu

This comment was marked as duplicate.

Copy link
Copy Markdown
Member

@doitchuu doitchuu left a comment

Choose a reason for hiding this comment

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

한주간 고생하셨습니다 다음 주에 뵈어요!

Comment on lines +15 to +16
const current = map[s[i]];
const next = map[s[i + 1]];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

변수로 빼니 코드 이해가 쉬운 것 같아요 👍

@sik9252 sik9252 merged commit 0fa9d4a into main Mar 22, 2026
1 check passed
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.

4 participants