Skip to content

[xeulbn] WEEK 02 solutions#2693

Merged
DaleSeo merged 4 commits into
DaleStudy:mainfrom
xeulbn:main
Jul 6, 2026
Merged

[xeulbn] WEEK 02 solutions#2693
DaleSeo merged 4 commits into
DaleStudy:mainfrom
xeulbn:main

Conversation

@xeulbn

@xeulbn xeulbn commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📊 xeulbn 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
3sum Medium ✅ 의도한 유형
climbing-stairs Easy ✅ 의도한 유형
contains-duplicate Easy ✅ 의도한 유형
house-robber Medium ✅ 의도한 유형
longest-consecutive-sequence Medium ✅ 의도한 유형
product-of-array-except-self Medium ✅ 의도한 유형
top-k-frequent-elements Medium ✅ 의도한 유형
two-sum Easy ✅ 의도한 유형
valid-anagram Easy ✅ 의도한 유형
validate-binary-search-tree Medium ✅ 의도한 유형

누적 학습 요약

  • 풀이한 문제: 5 / 75개
  • 이번 주 유형 일치율: 100% (10문제 중 10문제 일치)

문제 풀이 현황

카테고리 진행도 완료
Heap ■■□□□□□ 1 / 3 (Medium 1)
Array ■□□□□□□ 2 / 10 (Easy 2)
Graph ■□□□□□□ 1 / 8 (Medium 1)
Dynamic Programming ■□□□□□□ 1 / 11 (Medium 1)
Binary □□□□□□□ 0 / 5 ← 아직 시작 안 함
Interval □□□□□□□ 0 / 5 ← 아직 시작 안 함
Linked List □□□□□□□ 0 / 6 ← 아직 시작 안 함
Matrix □□□□□□□ 0 / 4 ← 아직 시작 안 함
String □□□□□□□ 0 / 10 ← 아직 시작 안 함
Tree □□□□□□□ 0 / 14 ← 아직 시작 안 함

🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다.

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 3,688 436 4,124 $0.000359
2 3,688 459 4,147 $0.000368
합계 7,376 895 8,271 $0.000727

@xeulbn xeulbn moved this to In Review in 리트코드 스터디 8기 Jul 2, 2026
Comment thread 3sum/xeulbn.java

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Sorting, Hash Map / Hash Set
  • 설명: 3Sum 문제에서 정렬 후 두 포인터를 활용해 합이 0이 되면 정답을 수집하고, 합이 작으면 왼쪽 포인터를, 크면 오른쪽 포인터를 이동합니다. 중복 제거를 위한 추가 조건도 포함되어 있어 Two Pointers 패턴이 핵심입니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: Solution.threeSum — Time: O(n^2) / Space: O(1)
복잡도
Time O(n^2)
Space O(1)

피드백: 정렬과 두 포인터 탐색으로 중복을 제거하고 필요 시 건너뛰기 처리까지 잘 구현되어 있습니다.

개선 제안: 현재 구현이 적절해 보입니다.

풀이 2: Solution.threeSum — Time: O(n^2) / Space: O(1)
복잡도
Time O(n^2)
Space O(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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Greedy
  • 설명: 피보나치 형태의 부분 문제를 해결하며, DP로 각 단계의 최적 해를 저장하고 이를 이용해 최종 해를 구한다. 공간 최적화 여지가 있지만 본 코드에서는 배열을 사용한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 정확한 동작과 적절한 초기값 설정으로 선형 시간/공간 복잡도를 만족합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy
  • 설명: 중복 여부를 확인하기 위해 해시 세트를 사용하여 한 번 방문한 값은 재방문 여부를 빠르게 체크하는 방식으로 중복 탐지를 수행합니다. 전형적인 해시 기반 탐색으로, 시간 복잡도는 O(n), 추가 공간은 O(n) 입니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: Solution.containsDuplicate — Time: O(n) / Space: O(n)
복잡도
Time O(n)
Space O(n)

피드백: 해시 세트를 이용한 선형 시간 검사로 최적의 해결

개선 제안: 현재 구현이 적절해 보입니다.

풀이 2: Solution.containsDuplicate — Time: O(n) / Space: O(n)
복잡도
Time O(n)
Space O(n)

피드백: 해시 세트를 이용한 선형 시간 검사로 최적의 해결

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Comment thread house-robber/xeulbn.java

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 배열의 부분 문제로 최대 금액을 구하는 점화식 dp[i] = max(dp[i-1], dp[i-2] + nums[i])를 이용한 전형적인 DP 풀이이며, 중복 계산을 피하기 위한 최적 부분구조를 활용합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 연속되게 커지는 값을 피하기 위한 최적 부분구조를 올바르게 활용

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy, Two Pointers
  • 설명: 집합에 존재 여부를 빠르게 확인하고, 시작점에서 연속 부분을 확장하는 방식으로 최댓값을 구하므로 해시 세트와 탐색 방향의 확장으로 구성된 그리디/투 포인터 유사 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 각 수를 한 번씩만 탐색하는 방식으로 최적의 시간 복잡도 확보

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Hash Map / Hash Set, Dynamic Programming
  • 설명: 배열의 각 원소를 곱으로 만들되 자기 자신은 제외하는 결과를 구하기 위해, 좌우 누적곱을 각각 미리 계산한 뒤 곱해 최종 값을 얻는 방식으로 진행합니다. 공간을 상수 배치로 유지하기 위해 결과 배열을 활용하는 점이 특징입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 두 패스 방식으로 불필요한 나눗셈 없이 구현

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

@namuuCY namuuCY 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.

2주차까지 수고하셨습니다!

Comment thread 3sum/xeulbn.java
@@ -0,0 +1,52 @@
import java.util.*;

//시간복잡도 : O(n^2), 공간복잡도 : O(nlogn)

@namuuCY namuuCY Jul 2, 2026

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.

혹시 이거 왜 공간복잡도가 O(n log n)이 되는지 설명해주실 수 있나요?
sort에 쓰이는 추가 공간복잡도가 logn 정도는 될 것 같은데.. 그것외에는 nlogn까지 올라가는 이유가 코드상으로는 와닿지 않아서 여쭤봅니다!

Comment on lines +3 to +4
//시간복잡도 : O(n), 공간복잡도 : O(n)
//이전 두 값만 필요하기에, 공간복잡도는 O(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.

공간 최적화가 잘 되어서 좋은 것 같습니다!

Comment thread house-robber/xeulbn.java
Comment on lines 1 to 21

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.

이 문제도 위의 climb stairs 문제와 비슷하게 최적화가 가능할것 같아요!

Comment on lines 10 to 12

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.

우선순위큐를 둬서 나중에 순서정렬 안한 것은 좋은 아이디어 같습니다!
이렇게 풀이를 할 때, 시공간 복잡도가 어떻게 될지 주석으로 적어두면 좋을 것 같습니다!

@Zero-1016 Zero-1016 self-requested a review July 2, 2026 15:12

@Zero-1016 Zero-1016 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.

고생하셨습니다 :) java 코드로 풀이하신거보니 재밌네요.

DaleStudy 레포지토리가 기본적으로 Squash Merge를 지원하고 있어서 지난주에 풀이하신 문제 5개가 변경사항으로 들어왔어요.

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.

Java에는 우선순위 큐라는 개념이 존재하군요. 새롭게 알아갑니다.

Comment thread 3sum/xeulbn.java
class Solution {
public List<List<Integer>> threeSum(int[] nums) {

Arrays.sort(nums);

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.

TMI) js는 기본이 문자열 정렬이라 이 풀이를 그대로 js로 옮기면 틀려요 java 좋네요

[10, 2, 1].sort();            // → [1, 10, 2]  😱  비교자 없으면 문자열 정렬
[10, 2, 1].sort((a,b)=>a-b);  // → [1, 2, 10]  이렇게 해야 함

@parkhojeong parkhojeong 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.

다른 분들이 리뷰 꼼꼼하게 해주셨네요! 몇가지 커멘트 남겼습니다~ 수고하셨습니다!

Comment thread 3sum/xeulbn.java
Comment on lines +21 to +32
if(sum==0){
// 정답 추가
List<Integer> tmpList = new ArrayList<>();
tmpList.add(nums[i]);
tmpList.add(nums[leftIndex]);
tmpList.add(nums[rightIndex]);

answer.add(tmpList);

// left++, right--
leftIndex+=1;
rightIndex-=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.

List.of를 사용하면 tmpList 를 사용 안해도 될거 같고, 정답추가와 left++, right-- 주석은 코드로 충분히 설명이 되어서 없어도 괜찮을 거 같습니다! :)

Suggested change
if(sum==0){
// 정답 추가
List<Integer> tmpList = new ArrayList<>();
tmpList.add(nums[i]);
tmpList.add(nums[leftIndex]);
tmpList.add(nums[rightIndex]);
answer.add(tmpList);
// left++, right--
leftIndex+=1;
rightIndex-=1;
if(sum==0){
answer.add(List.of(nums[i], nums[leftIndex], nums[rightIndex]));
leftIndex+=1;
rightIndex-=1;

return n;
}

int[] dp =new int[n+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.

대체로 할당/산술 연산자 좌우로 스페이스를 한 칸 쓰시는 게 많은게 일관되게 맞춰주시면 좋을 거 같습니다! 문제마다 조금씩 다르네요 :)

Suggested change
int[] dp =new int[n+1];
int[] dp = new int[n+1];

Comment thread two-sum/xeulbn.java
Comment on lines 5 to 8

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.

변수 명을 공들여서 쓰시는 느낌이 드는 거 같습니다! 좋네요 :)

Comment thread valid-anagram/xeulbn.java
Comment on lines +22 to +30
if(!characterMap.containsKey(c)){
return false;
}

characterMap.put(c, characterMap.get(c) - 1);
if(characterMap.get(c)<0){
return 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.

characterMap.get(c)<0은 조건식을 합쳐도 좋을 거 같습니다 :)

Suggested change
if(!characterMap.containsKey(c)){
return false;
}
characterMap.put(c, characterMap.get(c) - 1);
if(characterMap.get(c)<0){
return false;
}
}
if(!characterMap.containsKey(c) || characterMap.get(c)<=0){
return false;
}
characterMap.put(c, characterMap.get(c) - 1);
}

Comment on lines +23 to +39
class Solution {
public boolean isValidBST(TreeNode root) {
return validate(root, Long.MIN_VALUE, Long.MAX_VALUE);
}

private boolean validate(TreeNode node, long min, long max) {
if (node == null) {
return true;
}

if (node.val <= min || node.val >= max) {
return false;
}

return validate(node.left, min, node.val) && validate(node.right, node.val, max);
}
}

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.

코드가 매우 깔끔해서 좋은 거 같습니다 :)

@DaleSeo DaleSeo merged commit 6312f3f into DaleStudy:main Jul 6, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 8기 Jul 6, 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.

5 participants