Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[강희찬] WEEK 8 Solution #502

Merged
merged 7 commits into from
Oct 6, 2024
Merged

[강희찬] WEEK 8 Solution #502

merged 7 commits into from
Oct 6, 2024

Conversation

HC-kang
Copy link
Contributor

@HC-kang HC-kang commented Sep 29, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@HC-kang HC-kang marked this pull request as ready for review October 2, 2024 00:16
@HC-kang HC-kang requested a review from a team as a code owner October 2, 2024 00:16
Copy link
Contributor

@TonyKim9401 TonyKim9401 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 +12 to +22
function dfs(node: _Node): _Node {
if (map.has(node.val)) return map.get(node.val)!;

const newNode = new _Node(node.val);
map.set(node.val, newNode);

for (let neighbor of node.neighbors) {
newNode.neighbors.push(dfs(neighbor));
}

return newNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

결국 문제를 풀기 위해서는 재귀적으로 풀어야 하는데, 주어진 cloneGraph 자체를 재귀 함수로 사용하는 방법도 괜찮은것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아래와 같은 형태로 해당 함수의 params를 변경한다면 cloneGraph를 직접 재귀함수로 사용해도 최적의 풀이가 가능할 것 같네요

function cloneGraph(node: _Node | null, map?: Map<number, _Node>): _Node | null {
...
}

current = current.next;
}

current.next = list1 || list2;
Copy link
Contributor

Choose a reason for hiding this comment

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

자스는 null이면 false를 반환하니 이게 가능하군요 :) 👍

Comment on lines +15 to +19
maxCount = Math.max(maxCount, ++charCount[endCharIdx]);

if (end - start + 1 - maxCount > k) {
charCount[s.charCodeAt(start) - A]--;
start++;
Copy link
Contributor

Choose a reason for hiding this comment

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

전위, 후위 연산을 사용 하시는 기준이 궁금해요 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

위 코드에서는 startend를 통해 윈도우의 크기를 줄이고 늘여가면서 maxCount를 계산하고있습니다

저는 일반적으로 연산 순서에 영향받지 않는다면 후위 연산을 선호하는데요, 별다른 이유는 없고 익숙해서 그렇습니다 ㅎㅎ
다만 전위 연산을 사용한 ++charCount[endCharIdx]의 경우에는 직전에 end가 +1로 증가한 상태이므로 maxCount와 비교하기 위해서는 Math.max()연산 이전에 증감을 시킬 필요가 있으므로 전위 연산자를 사용했습니다!

@HC-kang HC-kang merged commit f99d21c into DaleStudy:main Oct 6, 2024
1 check passed
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.

2 participants