-
-
Notifications
You must be signed in to change notification settings - Fork 195
[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
Conversation
if (min > prices[i]) { | ||
min = prices[i]; | ||
continue; | ||
} | ||
max = Math.max(max, prices[i] - min); |
There was a problem hiding this comment.
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이 될테니까요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우와 생각하지 못했던 부분을 정성스럽게 피드백 해주셔서 감사합니다!
덕분에 분기를 줄여봤는데 더 깔끔해진 것 같아요 ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번주도 수고하셨습니다! 🥰
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!