Skip to content

[freemjstudio] WEEK 05 Solutions#2773

Open
freemjstudio wants to merge 1 commit into
DaleStudy:mainfrom
freemjstudio:freemjstudio-week05
Open

[freemjstudio] WEEK 05 Solutions#2773
freemjstudio wants to merge 1 commit into
DaleStudy:mainfrom
freemjstudio:freemjstudio-week05

Conversation

@freemjstudio

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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

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

설정 방법

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

📚 자세한 가이드 보기


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

@dalestudy

dalestudy Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

📊 freemjstudio 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
best-time-to-buy-and-sell-stock Easy ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 368 56 424 $0.000041

@github-actions github-actions Bot added the py label Jul 24, 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Two Pointers
  • 설명: 최초 풀이엔 시간 복잡도 문제로 비효율적이지만, 두 번째 풀이에서 매일 최소 가격을 갱신하며 현재 가격과의 차이를 비교하는 방식은 그리디 패턴의 전형으로, 한 번의 순회로 최적해를 구한다. 또한 1차원 배열을 좌우로 단순한 포인터처럼 다루는 접근으로 간주 가능하다.

📊 시간/공간 복잡도 분석

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

피드백: 첫 시도는 모든 가능한 구매 시점을 기반으로 최대 이익을 계산해 시간 복잡도가 O(n^2)로 비효율적이다. 두 번째 시도에서 최소 가격과 누적 이익을 추적해 선형 시간으로 해결한다.

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

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

@dolphinflow86
dolphinflow86 self-requested a review July 25, 2026 03:12
Comment on lines +1 to +21
# first attempt - time out

class Solution:
def maxProfit(self, prices: List[int]) -> int:
max_profit = 0
for i in range(len(prices)):
profit = max(prices[i:]) - prices[i]
max_profit = max(max_profit, profit)
return max_profit

# second attempt - greedy approach
class Solution:
def maxProfit(self, prices: List[int]) -> int:
max_profit = 0
min_price = prices[0]

for i in range(len(prices)):
min_price = min(min_price, prices[i])
profit = prices[i] - min_price
max_profit = max(max_profit, profit)
return max_profit

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 +14 to +18
max_profit = 0
min_price = prices[0]

for i in range(len(prices)):
min_price = min(min_price, prices[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가 0인 경우 불필요한 재계산이 되서 1부터 시작하면 명확할 거 같습니다.

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

프로젝트 주차 설정과 pr 체크리스트도 확인 부탁드립니다.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants