-
-
Notifications
You must be signed in to change notification settings - Fork 195
[sun] WEEK 5 solution #450
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
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.
파이썬으로 간결하게 작성된 코드가 이해가 잘 되었습니다 고생하셨습니다!
l = 0 | ||
r = 1 | ||
|
||
while r < len(prices): |
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.
코드 내용 잘 보았습니다! two pointer를 이용한 솔루션 자체는 이해가 잘 되는데요 아래와 같은 방법으로 조금 더 간결하게 적을 수 있지 않을까 싶어 코멘트 드립니다 😄
max_profit=0
buy = 0 ## l,r 대신 사는날의 인덱스만 표기
for sell in range(1, len(prices)): ## while loop 대신 for loop을 이용해서 sell 포인터를 안으로 포함시켜버리기
이렇게 개선하면 조금 더 간결하게 쓸 수 있을거 같아요!
result.add((nums[i], nums[left], nums[right])) | ||
left,right = left+1, right-1 | ||
|
||
return list(result) |
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.
코드 전반적인 내용은 잘 이해가 됩니다만, 요 부분이 조금 신경이 쓰이네요 ㅎㅎ 혹시 result를 시작부터 list로 작성하는 방법도 생각해보셨을까요? 캐스팅을 하더라도 Time complexity가 유의미한 변화가 없는건 이해가 갑니다만, set을 사용하지 않으면 메모리 측면에서 조금 유리하지 않을까 생각이 드네요 😃
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.