Skip to content

Conversation

Chaedie
Copy link
Contributor

@Chaedie Chaedie commented Jan 21, 2025

답안 제출 문제

체크 리스트

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

@Chaedie Chaedie requested a review from a team as a code owner January 21, 2025 11:39
@github-actions github-actions bot added the py label Jan 21, 2025
@Chaedie Chaedie requested a review from yolophg January 21, 2025 11:40
Copy link
Contributor

@obzva obzva left a comment

Choose a reason for hiding this comment

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

안녕하세요 Chaedie님 :)
이번 한 주도 수고하셨습니다


class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
window = set()
Copy link
Contributor

@obzva obzva Jan 23, 2025

Choose a reason for hiding this comment

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

set으로 이미 방문한 문자들을 관리하는 대신에, dictionary로 { 방문한 문자: 해당 문자의 인덱스 }를 관리할 수도 있습니다 :)
참고하시라고 gist 남깁니다 https://gist.github.com/obzva/5db9d02a3e6c97f45589dab34f0f8603

Copy link
Contributor Author

@Chaedie Chaedie Jan 24, 2025

Choose a reason for hiding this comment

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

감사합니다.참고하겠습니다..!

prev = None
cur = head
while cur:
next = cur.next
Copy link
Contributor

Choose a reason for hiding this comment

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

개인적인 생각입니다, 변수명을 next로 지으니까 좀 헷갈리는 것 같아요
지금은 간단한 함수라 괜찮지만, 더 복잡해지면 좀 어지러울 수 있을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

node.next 와 next 라는 변수명이 겹쳐서 헷갈린다는 의미시죠? temp 로 수정하겠습니다. 👍

dp = []
for i in range(m):
dp.append([0] * n)
print(dp)
Copy link
Contributor

Choose a reason for hiding this comment

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

ㅎㅎㅎ 여기 디버깅하시고 깜빡하셨어요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

앗 ㅎㅎㅎㅎ

Comment on lines +28 to +30
up_value = 0 if i - 1 < 0 or i - 1 >= m else dp[i - 1][j]
left_value = 0 if j - 1 < 0 or j - 1 >= n else dp[i][j - 1]

Copy link
Contributor

Choose a reason for hiding this comment

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

이렇게 하시는 것보다 17번 줄 근처에서 애초에 dp를 m x n 크기의 2차원 배열로 초기화시키고 시작하는게 더 깔끔할 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

감사합니다.
dp 배열 만들 때 1로 초기화 시키고, 배열 인덱스 경계 체크 없이 1부터 m, 1부터 n 계산하도록 했습니다. 리뷰 주신대로 훨씬 깔끔해졌네요 감사해요 항상 👍 (반영이 늦어서 다음 PR 에 포함될 예정입니다 🙏)

def uniquePaths(self, m: int, n: int) -> int:
        dp = [[1] * n] * m

        for i in range(1, m):
            for j in range(1, n):
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1]

        return dp[m - 1][n - 1]

1) for iteration 을 도는 동안 hash set 을 이용해 처음 발견한 원소들을 window set에 넣는다.
2) 중복되는 원소를 발견할 경우 해당 원소의 중복이 사라질때까지 left side 의 원소들을 하나씩 제거한다.

Time: O(n^2) = O(n) (for iteration) * O(n) 최악의 경우 n만큼의 중복제거
Copy link
Contributor

Choose a reason for hiding this comment

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

각 문자마다 최대 2번의 연산만 실행됩니다

  • window에 추가하는 경우
  • window에서 삭제하는 경우
    그럼 시간 복잡도는 O(2N) = O(N)으로 계산되어야 할 것 같아요
    어떻게 생각하세요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

O(2N) => O(N) 이 맞는것 같습니다.
loop 내부에서 연산을 한다는 것만으로 관성적으로 곱셈으로 생각한것 같습니다. 감사합니다..!

@TonyKim9401 TonyKim9401 merged commit 3acc058 into DaleStudy:main Jan 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants