-
-
Notifications
You must be signed in to change notification settings - Fork 361
[Chanz] WEEK 07 Solutions #2803
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class Solution: | ||
| def lengthOfLongestSubstring(self, s: str) -> int: | ||
| left = 0 | ||
| max_len = 0 | ||
| visited = {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. visited는 단순히 방문했던 것만 담는 것처럼 느껴지는데요. 인덱스를 담는다는 걸 나타내는 건 어떨까요? |
||
|
|
||
| for right, ch in enumerate(s): | ||
| if ch in visited and visited[ch] >= left: | ||
| left = visited[ch] + 1 # 현재 윈도우 상에서 중복 문자가 발견되었기 때문에 윈도우를 중복 문자 이후로 옮김. | ||
|
|
||
| visited[ch] = right | ||
| max_len = max(max_len, right - left + 1) | ||
|
|
||
| return max_len | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석reverse-linked-list/Chanz82.py# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
dummy = ListNode()
dummy = head
prev = None
while dummy:
nextNode = dummy.next
dummy.next = prev
prev = dummy
dummy = nextNode
return prev
📊 시간/공간 복잡도 분석
피드백: 반전 과정에서 prev, nextNode를 이용해 노드의 연결을 뒤집는다. 루프 종료 후 prev가 새 head가 된다. 개선 제안: dummy 변수 할당이 불필요해 보이나 현재 로직은 올바르게 동작한다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Definition for singly-linked list. | ||
| # class ListNode: | ||
| # def __init__(self, val=0, next=None): | ||
| # self.val = val | ||
| # self.next = next | ||
| class Solution: | ||
| def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: | ||
| dummy = ListNode() | ||
| dummy = head | ||
|
Comment on lines
+8
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 8라인이 필요할까요? 바로 아래 코드에서 |
||
| prev = None | ||
|
|
||
| while dummy: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dummy는 어떤 값이 담기는지 알기가 어려운데요. 의미에 맞는 네이밍을 하시는 건 어떨까요? |
||
| nextNode = dummy.next | ||
| dummy.next = prev | ||
| prev = dummy | ||
| dummy = nextNode | ||
|
|
||
| return prev | ||
|
|
||
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.
🏷️ 알고리즘 패턴 분석
longest-substring-without-repeating-characters/Chanz82.py
📊 시간/공간 복잡도 분석
피드백: 각 문자의 마지막 위치를 저장하고 현재 인덱스와 비교해 왼쪽 포인터를 이동시키는 표준 슬라이딩 윈도우 방식이다.
개선 제안: 현재 구현이 적절해 보입니다.