Skip to content

[essaysir] WEEK 05 Solutions#2766

Open
essaysir wants to merge 3 commits into
DaleStudy:mainfrom
essaysir:week-05
Open

[essaysir] WEEK 05 Solutions#2766
essaysir wants to merge 3 commits into
DaleStudy:mainfrom
essaysir:week-05

Conversation

@essaysir

@essaysir essaysir commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

⚠️ Week 설정이 누락되었습니다

프로젝트에서 Week를 설정해주세요!

설정 방법

  1. PR 우측의 Projects 섹션에서 리트코드 스터디 옆 드롭다운(▼) 클릭
  2. 현재 주차를 선택해주세요 (예: Week 14(current) 또는 Week 14)

📚 자세한 가이드 보기


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

@github-actions github-actions Bot added the java label Jul 22, 2026
@dalestudy

dalestudy Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

📊 essaysir 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
best-time-to-buy-and-sell-stock Easy ✅ 의도한 유형
encode-and-decode-strings Medium ✅ 의도한 유형
group-anagrams Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 708 93 801 $0.000073
2 1,188 158 1,346 $0.000123
합계 1,896 251 2,147 $0.000195

@JeonJe
JeonJe self-requested a review July 22, 2026 11:04

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Two Pointers
  • 설명: 로직이 한 번의 순회로 최적의 차이를 구하는 Greedy 패턴이며, 최소의 가격 인덱스(앞부분 포인터)와 현재 가격과의 차이를 비교하는 Two Pointers 흐름이 같이 적용됩니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy, Divide and Conquer, Dynamic Programming, Two Pointers, Sliding Window, Fast & Slow Pointers, BFS, DFS, Backtracking, Union Find, Trie, Bit Manipulation, Monotonic Stack, Heap / Priority Queue, Binary Search
  • 설명: 문자열 인코딩 길이(prefix length)와 구분자('#')를 이용해 문자열을 순차적으로 파싱하는 방식으로, 문자열의 구성 요소를 순회하며 구분을 이용해 부분 문자열을 분리한다. 특정 데이터 단위를 분리하고 재구성하는 패턴에 해당한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(sum of lengths)
Space O(sum of lengths)

피드백: 정확히 각 문자열의 길이를 먼저 기록하고 문자열 자체를 이어붙이는 방식으로 인코딩합니다.

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

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

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, Divide and Conquer
  • 설명: 문자 문자열을 정렬한 키로 그룹화하여 같은 아나그램들을 묶는 방식으로 해시맵에 분류하는 패턴. 각 키로 그룹을 구성하고 최종 결과를 모으는 흐름이 특징이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n * k log k)
Space O(n * k)

피드백: 각 문자열 길이에 따라 정렬 비용이 지배적이며, 그룹화에 해시맵을 사용합니다.

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

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

List<List<String>> answer = new ArrayList<>();
Map<String, List<String>> map = new HashMap<>();

for ( int i = 0; i < strs.length; i ++) {

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.

루프 안에서 i 자체를 쓰지 않고 strs[i]로 값만 참조할 때 가독성을 향상시키기 위해서 enhanced for-loop을 써보는 것도 좋을 것 같습니다!

* @param strs: a list of strings
* @return: encodes a list of strings to a single string.
*/
public String encode(List<String> strs) {

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.

'#'이 encode/decode 양쪽에 매직 리터럴로 중복되기 때문에, private static final char DELIMITER = '#';로 추출해서 두 메서드의 인코딩 계약이 한 곳에서 관리되면 나중에 구분자 바꿀 때 한쪽만 수정하는 실수를 예방할 수 있을 것 같아요!

class Solution {
public int maxProfit(int[] prices) {
int result = 0;
// prices = [7,1,5,3,6,4]

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.

최소값 대신 최소 인덱스를 들고 가는 접근도 깔끔하네요.
인덱스로 잡으면 나중에 '며칠에 샀는지'까지 확장할 때 바로 쓸 수 있는 여지가 있어 좋네요!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

좋은 의견들 너무 감사합니다! 앞으로, 코딩 테스트 하면서 적용해볼 수 있도록 노력하도록 하겠습니다.

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

수고하셨습니다. 몇가지 커멘트 남겼습니다.

public int maxProfit(int[] prices) {
int result = 0;
// prices = [7,1,5,3,6,4]
int lt = 0;

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.

lt는 무슨 약어일까요? 추측하기 어려운 약어로 보여서 의미를 담는 변수명을 사용하시면 좋을 거 같아요.

Comment on lines +11 to +15
result = Math.max(result, prices[i] - prices[lt]);
}
}

return result;

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 on lines +7 to +14
StringBuilder sb = new StringBuilder();
for (String s : strs) {
sb.append(s.length());
sb.append('#');
sb.append(s);
}
return sb.toString();
}

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.

구분자 없이도 가능한데 풀어보셔도 좋을 거 같습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Solving

Development

Successfully merging this pull request may close these issues.

4 participants