-
-
Notifications
You must be signed in to change notification settings - Fork 248
[YeomChaeeun] Week 12 #1059
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 12 #1059
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,19 @@ | ||
|
||
/** | ||
* 알고리즘 복잡도 | ||
* - 시간 복잡도: O(nlogn) | ||
* - 공간 복잡도: O(1) | ||
*/ | ||
function eraseOverlapIntervals(intervals: number[][]): number { | ||
intervals.sort((a, b) => a[1] - b[1]) | ||
let end = intervals[0][1] | ||
let count = 0 | ||
for(let i = 1; i < intervals.length; i++) { | ||
if(intervals[i][0] < end) { | ||
count++ | ||
} else { | ||
end = intervals[i][1] | ||
} | ||
} | ||
return count | ||
} |
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,38 @@ | ||
/** | ||
* 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) | ||
* } | ||
* } | ||
*/ | ||
/** | ||
* n번째 노드 제거하기 | ||
* 알고리즘 복잡도 | ||
* - 시간 복잡도: O(n) | ||
* - 공간 복잡도: O(n) | ||
* @param head | ||
* @param n | ||
*/ | ||
function removeNthFromEnd(head: ListNode | null, n: number): ListNode | null { | ||
let stack: ListNode[] = []; | ||
let node = head; | ||
|
||
while (node) { | ||
stack.push(node); | ||
node = node.next; | ||
} | ||
|
||
// 첫 번째 노드를 제거하는 경우 추가 | ||
if (stack.length - n - 1 < 0) { | ||
return head?.next || null; | ||
} | ||
|
||
const prevNode = stack[stack.length - n - 1]; | ||
prevNode.next = prevNode.next?.next || null; | ||
|
||
return head; | ||
} |
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. 이야....... 전 개인적으로 좋아하는 코드네요 ㅎㅎ 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,29 @@ | ||
/** | ||
* Definition for a binary tree node. | ||
* class TreeNode { | ||
* val: number | ||
* left: TreeNode | null | ||
* right: TreeNode | null | ||
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { | ||
* this.val = (val===undefined ? 0 : val) | ||
* this.left = (left===undefined ? null : left) | ||
* this.right = (right===undefined ? null : right) | ||
* } | ||
* } | ||
*/ | ||
/** | ||
* 같은 트리인지 확인하기 | ||
* 알고리즘 복잡도 | ||
* - 시간 복잡도: O(n) | ||
* - 공간 복잡도: O(n) | ||
* @param p | ||
* @param q | ||
*/ | ||
function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { | ||
if(!p || !q) { | ||
return p === q; | ||
} | ||
|
||
return p.val === q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right) | ||
|
||
} |
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.
해당 문제는 LinkedList의 특성을 활용하여 푸는 문제라고 생각합니다!
Stack 으로 풀이하는것도 좋지만 LinkedList의 다음 노드를 가리키는 특성을 활용하여 다시 한번 풀어보시면 어떨까요?
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.
넵! 특성을 고려하는 방법으로도 풀어보겠습니다.
감사합니다!