Skip to content

Conversation

grapefruitgreentealoe
Copy link
Contributor

@grapefruitgreentealoe grapefruitgreentealoe commented Aug 23, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

let minPrice = Infinity;
let maxProfit = 0;

for (let price of prices) {
Copy link
Contributor

Choose a reason for hiding this comment

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

또는 const도 괜찮겠네요.


for (let price of prices) {
// 가장 싼 가격을 갱신
if (price < minPrice) {
Copy link
Contributor

Choose a reason for hiding this comment

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

또는 price - minPrice를 전처리해서 재사용한다면 음수일 때이겠네요.

for (let char of str) {
count[char.charCodeAt(0) - 97]++;
}
const key = count.join('#'); // 구분자 없으면 ["1","11"]과 ["11","1"] 같은 키로 오해 가능
Copy link
Contributor

Choose a reason for hiding this comment

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

또는 leading zeros를 넣어도 되겠군요.

return Array.from(map.values());
};

//시간복잡도 : O(n * k). 정렬이 없으므로
Copy link
Contributor

Choose a reason for hiding this comment

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

마찬가지로, Destructuring 연산 때문에 O(n * (k + n)) = O(n * k + n^2)이 되겠습니다.

count[char.charCodeAt(0) - 97]++;
}
const key = count.join('#'); // 구분자 없으면 ["1","11"]과 ["11","1"] 같은 키로 오해 가능
map.set(key, [...(map.get(key) || []), str]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
map.set(key, [...(map.get(key) || []), str]);
map.set(key, map.get(key)??[]).push(str);

마찬가지로, Destructuring을 피하면 O(n)O(1)로 줄겠습니다.
Nullish Coalescing Operator를 사용해도 좋겠습니다.


/*
시간복잡도: O(n^2) + 메모이제이션으로 최적화
공간복잡도 : O(n) : 재귀스택, failed set
Copy link
Contributor

Choose a reason for hiding this comment

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

wordSet 때문에 m = wordDict.length를 더해야 합니다: O(n + m)

};

/*
시간복잡도: O(n^2) + 메모이제이션으로 최적화
Copy link
Contributor

Choose a reason for hiding this comment

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

얼마나 최적화했는지 계산할 수 있습니다. sliceO(n)이므로 총 O(n^3)입니다.


/*
시간복잡도: O(n^2)
공간복잡도 : O(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

마찬가지로, wordSet 때문에 m = wordDict.length를 더해야 합니다: O(n + m)

};

/*
시간복잡도: O(n^2)
Copy link
Contributor

Choose a reason for hiding this comment

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

마찬가지로, sliceO(n)이므로 총 O(n^3)입니다.

for (let j = 0; j < i; j++) {
if (dp[j] && wordSet.has(s.slice(j, i))) {
dp[i] = true;
break; // 더 이상 검사 안 해도 됨
Copy link
Contributor

Choose a reason for hiding this comment

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

가지치기(Pruning) 가능할 줄 몰랐는데 배워갑니다!

@grapefruitgreentealoe
Copy link
Contributor Author

@yhkee0404 상세한 리뷰 감사합니다!!

@grapefruitgreentealoe grapefruitgreentealoe merged commit 561b930 into DaleStudy:main Aug 24, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 5기 Aug 24, 2025
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