-
Notifications
You must be signed in to change notification settings - Fork 125
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
[ganu] Week9 #983
Merged
Merged
[ganu] Week9 #983
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3481e87
feat: 141. Linked List Cycle
gwbaik9717 3276ce1
feat: 152. Maximum Product Subarray
gwbaik9717 abf4820
refactor: feat: 152. Maximum Product Subarray
gwbaik9717 2bd54e9
feat: 153. Find Minimum in Rotated Sorted Array
gwbaik9717 0cfc687
feat: 417. Pacific Atlantic Water Flow
gwbaik9717 26c6d4f
feat: 76. Minimum Window Substring
gwbaik9717 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 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,32 @@ | ||
// Time complexity: O(logn) | ||
// Space complexity: O(1) | ||
|
||
/** | ||
* @param {number[]} nums | ||
* @return {number} | ||
*/ | ||
var findMin = function (nums) { | ||
let left = 0; | ||
let right = nums.length - 1; | ||
|
||
while (left < right) { | ||
const mid = Math.floor((left + right) / 2); | ||
|
||
if (nums.at(mid - 1) > nums.at(mid)) { | ||
return nums[mid]; | ||
} | ||
|
||
if (nums.at(mid + 1) < nums.at(mid)) { | ||
return nums[mid + 1]; | ||
} | ||
|
||
if (nums.at(mid + 1) > nums.at(right)) { | ||
left = mid + 1; | ||
continue; | ||
} | ||
|
||
right = mid - 1; | ||
} | ||
|
||
return nums[left]; | ||
}; |
This file contains 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,22 @@ | ||
// Time complexity: O(n) | ||
// Space complexity: O(1) | ||
|
||
/** | ||
* @param {ListNode} head | ||
* @return {boolean} | ||
*/ | ||
var hasCycle = function (head) { | ||
let turtle = head; | ||
let rabbit = head; | ||
|
||
while (turtle && rabbit && rabbit.next) { | ||
turtle = turtle.next; | ||
rabbit = rabbit.next.next; | ||
|
||
if (turtle === rabbit) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}; | ||
gwbaik9717 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,31 @@ | ||
// Time complexity: O(n) | ||
// Space complexity: O(n) | ||
|
||
/** | ||
* @param {number[]} nums | ||
* @return {number} | ||
*/ | ||
var maxProduct = function (nums) { | ||
let answer = nums[0]; | ||
const products = Array.from({ length: nums.length + 1 }, () => null); | ||
products[0] = [1, 1]; // [min, max] | ||
|
||
for (let i = 1; i < products.length; i++) { | ||
const cases = []; | ||
|
||
// case 1 | ||
cases.push(nums[i - 1]); | ||
|
||
// case 2 | ||
cases.push(nums[i - 1] * products[i - 1][0]); | ||
|
||
// case 3 | ||
cases.push(nums[i - 1] * products[i - 1][1]); | ||
Comment on lines
+16
to
+23
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. 주석으로 케이스를 구분해주셔서 코드를 읽기 쉬웠습니다! 이번 주도 고생하셨습니다 😊 |
||
|
||
const product = [Math.min(...cases), Math.max(...cases)]; | ||
products[i] = product; | ||
answer = Math.max(answer, product[1]); | ||
} | ||
|
||
return answer; | ||
}; |
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.
mid 값의 경계에 대한 조건을 없애면 코드를 더 단순화할 수 있을 것 같습니다!