Skip to content

[Yn3-3xh] WEEK 05 Solutions #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

[Yn3-3xh] WEEK 05 Solutions #1402

wants to merge 2 commits into from

Conversation

Yn3-3xh
Copy link
Contributor

@Yn3-3xh Yn3-3xh commented May 1, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

Comment on lines 14 to 18
if (min > prices[i]) {
min = prices[i];
continue;
}
max = Math.max(max, prices[i] - min);
Copy link
Contributor

Choose a reason for hiding this comment

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

회고가 있는게 좋네요👍
저는 공간복잡도를 O(1)으로 만드는 부분이 어려웠던거 같아요!


최저가가 갱신되는 날은 판매하면 무조건 최대 이익이 아니다라는 관점에서 이해했는데,
이 부분이 이해하기 살짝 어렵게 느껴져서 Math.min()을 사용해서, 분기를 줄일 수도 있겠네요!

min = Math.min(min, prices[i]); 
max = Math.max(max, prices[i] - min);   

continue가 없어서 max가 계산되어도, 값은 max 혹은 0이 될테니까요

Copy link
Contributor Author

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.

2 participants