Skip to content

[hyejj19] WEEK 02 solutions#2407

Merged
hyejj19 merged 4 commits intoDaleStudy:mainfrom
hyejj19:main
Mar 14, 2026
Merged

[hyejj19] WEEK 02 solutions#2407
hyejj19 merged 4 commits intoDaleStudy:mainfrom
hyejj19:main

Conversation

@hyejj19
Copy link
Contributor

@hyejj19 hyejj19 commented Mar 11, 2026

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@github-actions github-actions bot added the ts label Mar 11, 2026
@hyejj19 hyejj19 marked this pull request as ready for review March 11, 2026 02:15
Copilot AI review requested due to automatic review settings March 11, 2026 02:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Week 02 solution submissions for the LeetCode study repo (issues #218 Valid Anagram, #230 Climbing Stairs) under the author handle hyejj19.

Changes:

  • Added a TypeScript solution for Valid Anagram using Map-based counting.
  • Added a TypeScript solution for Climbing Stairs using recursive memoization.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
valid-anagram/hyejj19.ts Implements an anagram check using character frequency maps (includes two alternative approaches).
climbing-stairs/hyejj19.ts Implements memoized recursion for counting distinct ways to climb stairs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// 2. 나머지 문자열을 순회하며 해당 문자열 카운트를 Map 에서 조회
// 3. 만약 카운트가 0이라면 false
// 4. 조회가 가능하다면 Map 의 카운트를 -1.
function isAnagram(s: string, t: string): boolean {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

isAnagram is declared/implemented twice in the same file (the second definition overwrites the first at runtime, and TypeScript tooling will report a duplicate implementation). If you want to keep both approaches, rename one (e.g., isAnagram1/isAnagram2) or comment/remove the unused version so there’s only a single exported solution entrypoint.

Suggested change
function isAnagram(s: string, t: string): boolean {
function isAnagram2(s: string, t: string): boolean {

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +15
const sMap = new Map();
for (const sChar of s) {
sMap.set(sChar, (sMap.get(sChar) || 0) + 1);
}
const tMap = new Map();
for (const tChar of t) {
tMap.set(tChar, (tMap.get(tChar) || 0) + 1);
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

new Map() is used without type parameters, which makes the map effectively Map<any, any> and loses type-safety. Consider using new Map<string, number>() (and similarly for tMap) so get/set are typed and you can avoid repeated casts/any propagation.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +8
function climbStairs(n: number, memo = {}): number {
// 재귀 종료조건
if (n === 1) return 1;
if (n === 2) return 2;

// 값이 메모에 존재하면 해당 값을 리턴
if (memo[n] !== undefined) return memo[n];

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

memo is currently an untyped object (memo = {}) and then indexed with memo[n], which becomes any in TypeScript and can trip stricter TS settings. Consider typing it as Record<number, number> (or using a number[]/Map<number, number>) and updating the signature accordingly so memoization is type-safe.

Copilot uses AI. Check for mistakes.
@nowrobin nowrobin self-requested a review March 11, 2026 04:51
@hyejj19 hyejj19 moved this to In Review in 리트코드 스터디 7기 Mar 13, 2026
@hyejj19
Copy link
Contributor Author

hyejj19 commented Mar 14, 2026

@DaleStudy 리뷰해줘

@dalestudy
Copy link
Contributor

dalestudy bot commented Mar 14, 2026

좋은 점이 많네요! 두 번째 접근법은 공간 효율성을 높인 좋은 시도입니다. 특히 최적화된 productExceptSelf 구현은 공간복잡도를 O(1)로 유지하는 훌륭한 해결책입니다. 또한, 전체적인 코드 가독성도 높고, 주석으로 이해를 돕고 있어 학습에 도움이 됩니다.

몇 가지 피드백을 드리자면:

  1. 시간/공간 복잡도 표기: 각 솔루션의 시간/공간 복잡도를 코드에 주석으로 명확히 표기하는 것이 좋겠습니다. 예를 들어, climbStairs는 TC: O(n), SC: O(1) (두 변수만 사용)으로 명시하면 더 좋습니다.

  2. climbStairs의 두 번째 구현은 최적이며, 반복문으로 변경하여 콜스택 과부하 문제를 해결한 점 잘하셨습니다. 다만, cur이 마지막에 할당되지 않는 경우 (n이 1 또는 2일 때)도 고려했지만, 현재 구조는 문제없어 보입니다.

  3. productExceptSelf는 공간 최적화에 성공적입니다. 다만, answer 배열을 처음부터 할당하는 것도 가독성을 높일 수 있습니다. 그리고 변수명을 좀 더 직관적으로 변경하거나, acc 대신 leftProd, rightProd 같은 의미 전달이 좋은 선택입니다.

  4. isAnagram의 두 번째 방법은 효율적입니다. 다만, 마지막에 모든 글자가 정확히 0인지 검증하는 검사가 필요할 수 있는데, 현재는 충분히 안전합니다. 만약 조금 더 엄격하게 하고 싶다면, 모든 값이 0인지 한 번 더 체크하는 것도 고려하세요.

전반적으로 깔끔하고 효율적입니다! 더 나은 성능과 가독성을 위해 주석과 변수명에 신경 쓰면 더욱 훌륭한 코드가 될 것 같습니다. 계속해서 발전하는 모습 기대할게요!

@hyejj19
Copy link
Contributor Author

hyejj19 commented Mar 14, 2026

@DaleStudy 승인해줘

@dalestudy
Copy link
Contributor

dalestudy bot commented Mar 14, 2026

이 PR은 두 문제(클라임스테어, 프로덕트 오브 어레이, 유효한 애그램)에 대해 효과적인 솔루션을 제시하고 있으며, 깔끔한 코드와 최적화도 보입니다. 특히, 클라임스테어의 반복문 방식과 프로덕트 계산법, 애그램 비교 방법 모두 좋은 접근입니다. 검토 후 승인하겠습니다!

Copy link
Contributor

@nowrobin nowrobin left a comment

Choose a reason for hiding this comment

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

이번한주도 문제풀이 고생하셨습니다, 다음주도 화이팅 입니다!

@hyejj19 hyejj19 merged commit 8548141 into DaleStudy:main Mar 14, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 7기 Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

3 participants