Skip to content

Conversation

jinvicky
Copy link
Contributor

@jinvicky jinvicky commented Aug 24, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@jinvicky jinvicky moved this from Solving to In Review in 리트코드 스터디 5기 Aug 24, 2025
@yhkee0404 yhkee0404 self-requested a review August 24, 2025 22:33

while (start < end) {
int y = Math.min(height[start], height[end]); // y축은 더 작은 값으로 설정
int x = Math.abs(start - end);
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
int x = Math.abs(start - end);
int x = end - start;

stack.pop();
} else if (stack.peek() == '{' && c == '}') {
stack.pop();
}
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
}
} else {
return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 조기 종료 생각을 못했네요! 감사합니다

Comment on lines +25 to +31
if (stack.peek() == '(' && c == ')') {
stack.pop();
} else if (stack.peek() == '[' && c == ']') {
stack.pop();
} else if (stack.peek() == '{' && c == '}') {
stack.pop();
}
Copy link
Contributor

@yhkee0404 yhkee0404 Aug 25, 2025

Choose a reason for hiding this comment

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

Suggested change
if (stack.peek() == '(' && c == ')') {
stack.pop();
} else if (stack.peek() == '[' && c == ']') {
stack.pop();
} else if (stack.peek() == '{' && c == '}') {
stack.pop();
}
if (stack.peek() == '(' && c == ')'
|| stack.peek() == '[' && c == ']'
|| stack.peek() == '{' && c == '}') {
stack.pop();
}

@yhkee0404
Copy link
Contributor

다음 2문제를 제출하셨는데 본문에 누락되었으니 추가해 주세요:

if (ch == '.') {
// 모든 가능 문자로 한 글자 매칭
for (int c = 0; c < 26; c++) {
if (node.next[c] != null && dfs(word, idx + 1, node.next[c])) {
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
if (node.next[c] != null && dfs(word, idx + 1, node.next[c])) {
if (dfs(word, idx + 1, node.next[c])) {


private static class Node {
Node[] next = new Node[26];
boolean isEnd;
Copy link
Contributor

Choose a reason for hiding this comment

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

isEmpty는 함수이므로 저는 endended처럼 표현합니다.

/**
* 구하려는 것은 최대 영역값이기 때문에 x,y축을 계산한 현재 영역과 기존 영역을 비교해 max값을 반환하면 됩니다.
* 포인터를 어떻게 좁힐까 생각할 수 있는데 쉽게 말해서 start와 end 중 더 작은 쪽을 앞 또는 뒤로 이동하면 됩니다.
* 영역은 두 막대가 모두 충족가능한 길이가 되어야 하므로 Math.min()으로 설정합니다.
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
* 영역은 막대가 모두 충족가능한 길이가 되어야 하므로 Math.min()으로 설정합니다.
* 영역의 높이는 막대가 모두 충족가능한 길이가 되어야 하므로 Math.min()으로 설정합니다.


// 중요 연산은 더하기와 교체입니다.
// 가장 크다는 것: 주어진 인덱스와 꼬리 리스트의 길이가 같다. -> 새 subsequence가 생깁니다.
// 그렇지 않다는 것은 최댓값보다 더 작은 값이 있다는 것, 그 자리를 주어진 x로 교체한다.
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
// 그렇지 않다는 것은 최댓값보다 더 작은 값이 있다는 것, 그 자리를 주어진 x로 교체한다.
// 그렇지 않다는 것은 최댓값보다 더 작거나 같은 값이 있다는 것, 그 자리를 주어진 x로 교체한다.

* LIS = "주어진 수열에서 순서를 지키면서 고를 수 있는 원소 중, 값이 점점 커지도록 선택했을 때 만들 수 있는 가장 긴 부분 수열."
* brute force로 이중 for문을 사용하는 것은 비효율적입니다. 그래서 for문 + BS를 곁들였습니다.
*
* Arrays.binarySearch()는 정렬된 배열에서만 동작하므로 이 문제의 테스트 케이스에 맞지 않습니다.
Copy link
Contributor

Choose a reason for hiding this comment

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

후술하신 대로 원본 nums의 이분 탐색은 아니라는 말씀 같기는 합니다.
그래도 Stack의 길이를 별도의 변수 top으로 관리하면 Arrays.binarySearch(tails, 0, top, x)이 가능합니다.

}
// System.out.println(firstDp[n-2]); // ok

// 마지막 요소만 포함한 dp (첫번째 요소 포함 X)
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
// 마지막 요소만 포함한 dp (첫번째 요소 포함 X)
// 첫째 요소를 포함하지 않는 dp

Comment on lines +8 to +12
else if (nums.length == 2)
return Math.max(nums[0], nums[1]);
else if (nums.length == 3) {
return Math.max(Math.max(nums[0], nums[1]), nums[2]);
}
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
else if (nums.length == 2)
return Math.max(nums[0], nums[1]);
else if (nums.length == 3) {
return Math.max(Math.max(nums[0], nums[1]), nums[2]);
}

Comment on lines +15 to +19
// 첫째 요소만 포함한 dp (마지막 요소 포함 X)
int[] firstDp = new int[n - 1];
firstDp[0] = nums[0];
for (int i = 1; i < n - 1; i++) {
int prev2AndNowRob = (i - 2 < 0 ? 0 : firstDp[i - 2]) + nums[i];
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
// 첫째 요소만 포함한 dp (마지막 요소 포함 X)
int[] firstDp = new int[n - 1];
firstDp[0] = nums[0];
for (int i = 1; i < n - 1; i++) {
int prev2AndNowRob = (i - 2 < 0 ? 0 : firstDp[i - 2]) + nums[i];
// 첫째 요소도 포함할 수 있는 dp
int[] firstDp = new int[n];
firstDp[0] = nums[0];
firstDp[1] = Math.max(nums[0], nums[1]);
for (int i = 2; i < n; i++) {
int prev2AndNowRob = firstDp[i - 2] + nums[i];

Comment on lines +12 to +19
* [길이를 계산할 때 항상 해야 할까???] -> 아니다!
* 왜? 이미 내가 포함된 연속된 시퀀스는 maxLength를 비교하는 과정을 거쳤는데 굳이 또?
* <p>
* 배움: 일단 계산을 떠올린다. -> 그리고 그 계산을 언제(if) 수행할 것인지 조건을 설정한다. (항상 해도 되는가? 중복되지는 않는가?)
* <p>
* [성능에 대한 잘못된 생각]
* O(n)이라면 꼭 for문 1번으로 해결해야 한다는 잘못된 생각을 갖고 있었다.
* 첫 번째 루프가 O(n), 두 번째 루프가 O(n)이고, 두 개를 합치면 O(n + n)입니다.
Copy link
Contributor

Choose a reason for hiding this comment

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

좋은 관찰이시네요. DFS나 BFS 코드도 그렇고 Flood Fill도 그렇죠.

* <p>
* [후기]
* 처음에는 어 기존이랑... 지금이랑 별도 배열로 체크? 그런데 배열의 개수가 어디까지 늘어나지...?
* 항상 기억할 점은 최대 길이, 최소 길이와 같은 문제는 결과가 중요하지 어느 숫자로 이루어져있는지 알 필요가 없다.
Copy link
Contributor

@yhkee0404 yhkee0404 Aug 28, 2025

Choose a reason for hiding this comment

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

역시 다양한 접근을 위해 좋은 관찰이십니다. 결정 문제는 아니지만 비슷한 환원 같네요.

Comment on lines +5 to +7
if (nums.length == 2) {
return Math.max(nums[0], Math.max(nums[0] * nums[1], nums[1]));
}
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
if (nums.length == 2) {
return Math.max(nums[0], Math.max(nums[0] * nums[1], nums[1]));
}

Comment on lines +19 to +22
// 계속 더한 값
int keep = justNum * max[i-1];
// 이전 최소에 음수 곱해서 리버스
int reverse = justNum * min[i-1];
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
// 계속 더한 값
int keep = justNum * max[i-1];
// 이전 최소에 음수 곱해서 리버스
int reverse = justNum * min[i-1];
// 계속 곱한 구간들 중 최댓값 또는 최솟값
int keep = justNum * max[i-1];
// 이전 최소 또는 최대에 음수 곱하면 리버스
int reverse = justNum * min[i-1];

* 생각해보니 단순히 범위가 0부터 nums.length까지의 연속된 시퀀스라면
* 그냥 0부터 n까지 더했을 때의 원래 예상값에서 현재 nums의 합계를 빼면 되는 것이다.
*
* 최댓값, 최솟값을 구할때와 비슷하게 굳이 내용 안을 다 찾으려고 형식 자료구조에 얽매이지 않아도 된다.
Copy link
Contributor

Choose a reason for hiding this comment

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

하지만 결국 다 탐색하는 게 맞으니 그 경우와는 덜 비슷하다는 생각이 들어요. 반대로 Set 자료구조의 add, remove 연산을 숫자의 덧셈, 뺄셈으로 구현한 것에 불과할지도 모릅니다. 한편 XOR 연산도 가능합니다.

Comment on lines -17 to -18
// 또한 기존 [빈도수, 숫자]를 버려야만 올바른 답을 도출할 수 있었다.
// 2. [숫자, 빈도수]로 저장하는 것만 생각했더니 내부 정렬을 어떻게 하지 못해서 굉장히 고민했다. 정답은 반대였다.
Copy link
Contributor

Choose a reason for hiding this comment

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

Database의 Secondary Index 또는 Inverted Index와 비슷한 원리 같더라고요.

Comment on lines +8 to +22
int[][] dp = new int[m][n];
for (int i = 0; i < m; i++) {
dp[i][0] = 1;
}

for (int j = 0; j < n; j++) {
dp[0][j] = 1;
}

for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m - 1][n - 1];
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
int[][] dp = new int[m][n];
for (int i = 0; i < m; i++) {
dp[i][0] = 1;
}
for (int j = 0; j < n; j++) {
dp[0][j] = 1;
}
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m - 1][n - 1];
int[][] dp = new int[m + 1][n + 1];
dp[0][1] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m][n];

@jinvicky jinvicky merged commit 50f75bb into DaleStudy:main Aug 31, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 5기 Aug 31, 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