Skip to content

[WEEK07-1] 최준호#30

Merged
raejun92 merged 1 commit into
mainfrom
raejun
Mar 25, 2026
Merged

[WEEK07-1] 최준호#30
raejun92 merged 1 commit into
mainfrom
raejun

Conversation

@raejun92
Copy link
Copy Markdown
Collaborator

이렇게 풀었어요

1. Backspace String Compare

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

1) 복잡도 계산

시간 복잡도는 O(n + m)이다. n과 m은 각각 s와 t의 길이이다.
공간 복잡도는 O(n + m)이다. stack1과 stack2의 크기는 각각 s와 t의 길이까지 될 수 있기 때문이다.


2) 접근 아이디어

stack을 이용해서 문제를 풀었다.
stack에 문자를 넣다가 #이 나오면 stack에서 pop을 해주었다.
stack1과 stack2를 만들어서 각각 s와 t를 처리해주었다.
마지막에 stack1과 stack2를 문자열로 만들어서 비교해주었다.


3) 회고

처음에 문제 이해하는데 시간이 좀 걸렸다.
backspace를 space로 착각했다.
문제를 제대로 이해하고 나서 stack을 이용해서 문제를 풀었다.
O(n)의 풀이를 보면 뒤에서부터 비교해가면서 #이 나오면 #과 그 앞의 문자를 건너뛰는 방식으로 풀이한다.



2. Counting Bits

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

1) 복잡도 계산

시간 복잡도는 O(nlogn)이다. n은 입력값이다.
공간 복잡도는 O(n)이다. result 배열의 크기는 n + 1이기 때문이다.


2) 접근 아이디어

0부터 n까지의 수를 2진수로 바꾼다.
2진수 문자열을 split으로 나누고 filter로 1인 것만 남긴다.
남은 문자열을 join으로 합쳐서 길이를 구한다.
길이를 result 배열에 push한다.


3) 회고

많은 메서드를 이용해서 풀이를 했는데 비트연산을 이용한 점화식 풀이를 보았다.
많은 지식을 알고 있으면 풀이 방법이 다양해지는 것 같다.



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.

이번 주도 고생 많으셨습니다 👍

}

return stack1.join("") === stack2.join("");
};
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 approved these changes Mar 25, 2026
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.

스택을 활용한 정석 풀이로 잘 구현하신 것 같네요, 이미 말씀해주신 부분이긴하지만, s, t를 처리하는 로직이 거의 동일해서 보조 함수로 분리하면 더 깔끔할 것 같아요!!

Comment thread raejun/CountingBits.js
.split("")
.filter((num) => num === "1")
.join("").length;

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.

toString, split, filter, join 등 메서드 잘 활용하시는거같네요 ㅎㅎ

@raejun92 raejun92 merged commit 9f48c4b into main Mar 25, 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.

3 participants