-
-
Notifications
You must be signed in to change notification settings - Fork 245
[hi-rachel] WEEK 07 solutions #1886
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b21279
longest-substring-without-repeating-characters sol (py)
hi-rachel 880bf05
fix lint
hi-rachel a08ff79
number-of-islands sol (py)
hi-rachel 0e32e92
unique-paths sol (py)
hi-rachel cda9b06
unique-paths 공간 복잡도 최적화 sol (py)
hi-rachel df049c4
set-matrix-zeroes sol (py)
hi-rachel b786384
reverse-linked-list sol (py)
hi-rachel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,29 @@ def lengthOfLongestSubstring(self, s: str) -> int: | |
max_len = max(max_len, right - left + 1) | ||
|
||
return max_len | ||
|
||
|
||
# HashMap 풀이 | ||
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. |
||
def lengthOfLongestSubstring(s: str) -> int: | ||
if not s: | ||
return 0 | ||
|
||
left = 0 # 윈도우 시작점 | ||
max_length = 0 # 최대 길이 | ||
seen = {} # 문자의 마지막 등장 위치를 저장하는 해시맵 | ||
|
||
for right in range(len(s)): | ||
char = s[right] | ||
|
||
# 현재 문자가 윈도우 내에 이미 존재하는 경우 | ||
if char in seen and seen[char] >= left: | ||
# 윈도우 시작점을 중복 문자 다음 위치로 이동 | ||
left = seen[char] + 1 | ||
|
||
# 현재 문자의 위치 업데이트 | ||
seen[char] = right | ||
|
||
# 현재 윈도우 길이와 최대 길이 비교 후 업데이트 | ||
max_length = max(max_length, right - left + 1) | ||
|
||
return max_length |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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중 for문 썼는데 좋은 방법이 있네요. 좋은 공부가 되었습니다~