-
-
Notifications
You must be signed in to change notification settings - Fork 195
[Lyla] Week 07 #926
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
[Lyla] Week 07 #926
Conversation
while s[right] in chars: | ||
chars.remove(s[left]) | ||
left += 1 |
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.
while문으로 중복되는 문자를 찾을 때까지 한 문자 한 문자 지우는 로직을 좀 더 단순하게 바꿀 수 있을 것 같아요
저라면 set으로 chars를 관리하는 것 대신에 dictionary로 관리할 것 같습니다
이러면 연산량이 좀 줄어들어요
length = 0
left = 0
lookup = {}
for right, char in enumerate(s):
if char in lookup and lookup[char] >= left:
left = lookup[char] + 1
lookup[char] = right
length = max(length, right + 1 - left)
공간 복잡도: O(m * n) | ||
- dp 테이블을 사용하여 모든 셀에 대한 경로 수를 저장하므로 공간 복잡도는 O(m * n)입니다. |
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(m)으로 최적화할 수 있을까요?
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.
전체 2차원 배열을 유지할 필요 없이, 한 행만 유지하면서 정보를 갱신하면 되겠네요! 피드백 감사합니다 :)
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [1] * n
for row in range(1, m):
for col in range(1, n):
dp[col] += dp[col - 1]
return dp[-1]
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.
Lyla님 안녕하세요 :)
깔끔한 풀이와 설명 덕에 리뷰하기 편했습니다
코멘트를 조금 남겨놓았으니 병합 전에 확인 바랍니다
감사합니다
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.