Skip to content

[youngduck] WEEK 02 Solutions - #2939

Open
youngduck wants to merge 1 commit into
DaleStudy:mainfrom
youngduck:week2
Open

youngduck wants to merge 1 commit into
DaleStudy:mainfrom
youngduck:week2

Conversation

@youngduck

@youngduck youngduck commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@dalestudy

dalestudy Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

🤖 AI 리뷰(알고리즘 패턴, 시간/공간 복잡도, 학습 현황) 결과는 Checks 탭에서 볼 수 있어요.

@liza0525
liza0525 self-requested a review November 20, 2026 17:37

@liza0525 liza0525 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

사소한 의견들 남기고 갑니다! 풀이 보고 저도 많이 배워갑니다!

// 알파벳 인덱스를 배열로 할당해놓아서 빈도수만 올리게 처리 이중반복문을 없애기위해
const sAlphabetIndex=[...new Array(26)].map((item,idx)=>0);
const tAlphabetIndex=[...new Array(26)].map((item,idx)=>0);
// 길이가다르면 반복문 돌기도전에 false 반환

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이 부분을 아예 문자열을 배열로 변환하기 이전에, 제일 먼저 해주면 어떠실까요?

for(let i = 0; i<s.length; i++){
tAlphabetIndex[tArray[i].charCodeAt(0)-97]+=1;
sAlphabetIndex[sArray[i].charCodeAt(0)-97]+=1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

아스키 코드로 푸는 방식도 가능하겠네요! 좋은 아이디어 얻어갑니다 👍🏼

@@ -0,0 +1,23 @@
// 시간복잡도 : O(n) - 문자열을 배열로 변환하고 각 문자의 빈도수를 한번씩 확인, n은 두 문자열 중 긴 길이
// 공간복잡도 : O(n) - 문자열을 복사한 배열 사용, 알파벳 빈도 배열은 길이가 26으로 고정

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

climbing stairs 문제와 비교하여
두 문제 모두 '길이가 고정된 배열'을 사용하신 걸로 작성하셨는데
공간복잡도가 다르게 적혀 있어서 한 번 확인 부탁드립니다

// 최대 계단수 대신 n까지 계산하고 n+1 크기의 배열을 만들면 시간, 공간복잡도 모두 O(n)

function climbStairs(n: number): number {
// 누적 합이라 해야하나 결국 N STEP까지 구하는거는 N-1, N-2스텝의 경우의 수를 합해주면됨

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

해당 문제는 dp로 이해했습니다!
설명에 적어주신대로 이전에 구한 답을 이용해서 현재의 값을 구하는 방식이라서요 :)
누적합은 원본 배열이 먼저 존재하고, 그 배열의 값을 앞에서부터 더해 쌓는 방식이라 알고 있습니다

Comment thread 3sum/youngduck.ts
left+=1;
right-=1;

// 방금 넣은 조합과 중복되지않게 양쪽에서 같은 숫자들을 건너뜀

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

저는 예전에 파이썬으로 풀었을 때는 result를 set()으로 만들어서 풀었어 가지고
이런 체크를 따로 안 해줬었는데, 중복 체크하는 걸 신경을 써주셨네요!
훨씬 정석으로 풀어주신 것 같습니다 배워갑니다 👍🏼


function climbStairs(n: number): number {
// 누적 합이라 해야하나 결국 N STEP까지 구하는거는 N-1, N-2스텝의 경우의 수를 합해주면됨
const arr = [...new Array(46)].map((iitem)=>0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

오, 문제 조건을 이용하셔서 아예 배열을 고정 사이즈로 만들어서 해결하셨군요.
저는 dp[n] = dp[n-1] + dp[n-2] 점화식에 주목해서 let 변수로 캐싱하거나 Tabulation 용 배열을 쓰거나 했는데,
이렇게 접근이 가능한 점 배웠습니다..!

}

// JavaScript의 경우 배열의 동등비교는 참조를 비교하므로 문자열로 변환해서 각 알파벳의 빈도수가 같은지 확인
return JSON.stringify(tAlphabetIndex)===JSON.stringify(sAlphabetIndex);

Copy link
Copy Markdown
Contributor

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

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants