-
-
Notifications
You must be signed in to change notification settings - Fork 245
[hi-rachel] WEEK 10 solutions #1921
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,16 +1,33 @@ | ||
| """ | ||
| https://leetcode.com/problems/search-in-rotated-sorted-array/solutions/ | ||
| 문제: 회전된 오름차순 정렬된 배열 nums에서 target 값의 인덱스를 반환하라. | ||
| Idea: 이진 탐색 패턴 사용 | ||
| - in → 리스트 전체를 선형 탐색 (O(N)) | ||
| - index → 다시 처음부터 선형 탐색 (O(N)) | ||
| TC: O(logN) | ||
| Brute Force | ||
| TC: O(N) | ||
| SC: O(1) | ||
| """ | ||
|
|
||
| from typing import List | ||
|
|
||
|
|
||
| class Solution: | ||
| def search(self, nums: List[int], target: int) -> int: | ||
|
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. 아래 이분탐색 코드가 효율적 |
||
| if target in nums: | ||
| return nums.index(target) | ||
| else: | ||
| return -1 | ||
|
|
||
| """ | ||
| 문제: 회전된 오름차순 정렬된 배열 nums에서 target 값의 인덱스를 반환하라. | ||
| Idea: 이진 탐색 패턴 사용 | ||
| TC: O(logN), while 루프에서 매번 절반씩 줄 | ||
| SC: O(1) | ||
| """ | ||
| class Solution: | ||
| def search(self, nums: List[int], target: int) -> int: | ||
| left, right = 0, len(nums) - 1 | ||
|
|
||
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.
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.
그래프 문제는 Map, Dict를 사용해서 점과 점을 이어간다고 생각하시면 조금 이해하시는데 도움이 될수도 있을것 같아요!