-
-
Notifications
You must be signed in to change notification settings - Fork 245
[YeomChaeeun] Week 9 #988
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
[YeomChaeeun] Week 9 #988
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
65cefcc
feat: linked-list-cycle, find-minimum-in-rotated-sorted-array solution
YeomChaeeun 867f27f
fix: find-minimum-in-rotated-sorted-array
YeomChaeeun 60282fc
fix: linked-list-cycle 토끼와 거북이 알고리즘 적용
YeomChaeeun 4d79e3f
feat: maximum-product-subarray solution
YeomChaeeun 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,39 @@ | ||
/** | ||
* 정렬된 배열에서 최소값 찾기 | ||
* 알고리즘 복잡도 | ||
* - 시간 복잡도: O(logn) | ||
* - 공간 복잡도: O(1) | ||
* @param nums | ||
*/ | ||
function findMin(nums: number[]): number { | ||
// 풀이 1 - sort() 사용 | ||
// 시간 복잡도: O(nlogn) / 공간 복잡도: O(1) | ||
// nums.sort((a, b) => a - b) | ||
// return nums[0] | ||
|
||
// 풀이 2 - 배열이 정렬되어 있음을 활용한 풀이 | ||
// 시간 복잡도: O(n) / 공간 복잡도: O(1) | ||
// let min = nums[0]; | ||
// for(let i = 1; i < nums.length; i++) { | ||
// console.log(nums[i]) | ||
// min = Math.min(nums[i], min) | ||
// } | ||
// return min | ||
|
||
// 이분 탐색법 활용 | ||
// 절반씩 잘라서 nums[n-1] > nums[n] 의 지점을 찾는다 | ||
let low = 1; | ||
let high = nums.length - 1; | ||
while(low <= high) { | ||
let mid = Math.floor((low + high) / 2); | ||
if(nums[mid - 1] > nums[mid]) { | ||
return nums[mid]; | ||
} | ||
if(nums[0] < nums[mid]) { | ||
low = mid + 1; | ||
} else { | ||
high = mid -1; | ||
} | ||
} | ||
return nums[0] | ||
} |
YeomChaeeun marked this conversation as resolved.
Show resolved
Hide resolved
|
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 @@ | ||
/** | ||
* Definition for singly-linked list. | ||
* class ListNode { | ||
* val: number | ||
* next: ListNode | null | ||
* constructor(val?: number, next?: ListNode | null) { | ||
* this.val = (val===undefined ? 0 : val) | ||
* this.next = (next===undefined ? null : next) | ||
* } | ||
* } | ||
*/ | ||
/** | ||
* 순환되는 링크드 리스트 찾기 | ||
* 알고리즘 복잡도 | ||
* - 시간 복잡도: O(n) | ||
* - 공간 복잡도: O(n) | ||
* @param head | ||
*/ | ||
function hasCycle(head: ListNode | null): boolean { | ||
let set = new Set(); | ||
while(head !== null) { | ||
// set에 이미 존재하는지 확인 | ||
if(set.has(head)) return true | ||
set.add(head) | ||
head = head.next | ||
} | ||
return false | ||
} |
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.