-
-
Notifications
You must be signed in to change notification settings - Fork 341
[sadie100] WEEK 06 Solutions #2515
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
Open
sadie100
wants to merge
3
commits into
DaleStudy:main
Choose a base branch
from
sadie100:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−0
Open
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| 이분탐색으로 정렬 탐색. 최소값이 들어있는 범위를 바탕으로 계속 좁혀 간다 | ||
| 중간값을 기준값으로 잡고, 마지막 값보다 큰지 작은지 확인한다 | ||
| 기준값이 마지막 값보다 작을 경우, 최소값은 왼쪽 반쪽에 있거나 기준값임. ex) 5 1 2 3 4 | ||
| -> range를 왼쪽 반쪽으로 줄이고(기준값 포함) 해당 중간값을 기준값으로 잡는다 | ||
| 기준값이 마지막 값보다 클 경우, 최소값은 오른쪽 반쪽에 있음. ex) 3 4 5 1 2 | ||
| -> range를 오른쪽 반쪽으로 줄이고 해당 중간값을 기준값으로 잡는다 | ||
|
|
||
| 최종적으로 start, end가 같아지는 값이 최소값이 된다. | ||
|
|
||
| 시간복잡도 : O(LogN) -> N은 nums의 개수. 이분탐색 | ||
| */ | ||
|
|
||
| function findMin(nums: number[]): number { | ||
| let start = 0 | ||
| let end = nums.length - 1 | ||
|
|
||
| while (start < end) { | ||
| let target = Math.floor((start + end) / 2) | ||
| if (nums[target] < nums[end]) { | ||
| end = target | ||
| } else { | ||
| start = target + 1 | ||
| } | ||
| } | ||
|
|
||
| return nums[start] | ||
| } |
|
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. 🏷️ 알고리즘 패턴 분석
|
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| 스택을 만들어 s를 탐색하며 집어넣고, 허용되지 않은 괄호가 오면 false를 리턴한다 | ||
| - 허용하는 괄호 : 열려있는 괄호 (, {, [ 혹은 마지막 원소의 짝이 되는 닫는괄호 | ||
|
|
||
| 시간복잡도 : O(N) - N은 s의 length | ||
| 공간복잡도 : O(N) (괄호 배열 및 괄호 쌍) | ||
| */ | ||
|
|
||
| function isValid(s: string): boolean { | ||
| const stack = [] | ||
| const openBrackets = ['(', '{', '['] | ||
| const bracketMap = { | ||
| '(': ')', | ||
| '{': '}', | ||
| '[': ']', | ||
| } | ||
|
|
||
| for (const char of s) { | ||
| if (openBrackets.includes(char)) { | ||
| stack.push(char) | ||
| continue | ||
| } | ||
| const last = stack.at(-1) | ||
| if (char === bracketMap[last]) { | ||
| stack.pop() | ||
| continue | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| return stack.length === 0 | ||
| } |
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.
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.
🏷️ 알고리즘 패턴 분석