Skip to content
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

[kayden] Week 09 Solutions #526

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[kayden] Week 09 Solutions #526

wants to merge 1 commit into from

Conversation

kjb512
Copy link
Contributor

@kjb512 kjb512 commented Oct 11, 2024

답안 제출 문제

너무 늦게 올렸네요.. 면접이 많이 잡혀서 급하게 풀고 올립니다!

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@kjb512 kjb512 self-assigned this Oct 11, 2024
@github-actions github-actions bot added the py label Oct 11, 2024
@kjb512 kjb512 requested a review from lymchgmk October 11, 2024 18:57
@kjb512 kjb512 marked this pull request as ready for review October 11, 2024 18:58
@kjb512 kjb512 requested a review from a team as a code owner October 11, 2024 18:58
@kjb512 kjb512 changed the title Adds Solutions [kayden] Week 09 Solutions Oct 11, 2024
Copy link
Contributor

@lymchgmk lymchgmk left a comment

Choose a reason for hiding this comment

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

좋은 풀이 감사합니다. 이번 주도 고생 많으셨습니다.

# 공간복잡도: O(N)
def hasCycle(self, head: Optional[ListNode]) -> bool:

visited = set()
Copy link
Contributor

Choose a reason for hiding this comment

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

이미 방문한 node를 재방문하면 cycle이 존재한다는 풀이가 명확해서 좋은 것 같습니다. Follow up에 공간복잡도를 O(1)으로 해결해보라는 방법도 고민해보시면 좋을 것 같습니다.

Comment on lines +6 to +13
prev = 0
answer = float('-inf')
for num in nums:
if prev + num > num:
prev += num
else:
prev = num
answer = max(answer, prev)
Copy link
Contributor

Choose a reason for hiding this comment

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

이 문제의 경우 유명한게 Kadane 알고리즘도 있지만, 면접에서 divide and conquer로도 풀어보라는 경우가 많다고 하더라고요 참고해보시면 좋을 것 같습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

2 participants