-
-
Notifications
You must be signed in to change notification settings - Fork 336
[robinyoon-dev] WEEK 11 Solutions #2598
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * @param {number[][]} intervals | ||
| * @return {number[][]} | ||
| */ | ||
| var merge = function (intervals) { | ||
|
|
||
| let result = []; | ||
|
|
||
| let sortedIntervals = intervals.toSorted((a, b) => a[0] - b[0]); | ||
|
|
||
| for (let interval of sortedIntervals) { | ||
|
|
||
| if (result.length == 0) { | ||
| result.push(interval); | ||
| continue; | ||
| } | ||
|
|
||
| let intervalStart = interval[0]; | ||
| let intervalEnd = interval[1]; | ||
|
|
||
| let lastItemInResult = result[result.length - 1]; | ||
|
|
||
| let start = lastItemInResult[0]; | ||
| let end = lastItemInResult[1]; | ||
|
|
||
| let isIntervalStartInRange = intervalStart >= start && intervalStart <= end; | ||
|
|
||
| if (isIntervalStartInRange) { | ||
| if (intervalEnd > end) { | ||
| result[result.length - 1][1] = intervalEnd; | ||
| } | ||
| } else { | ||
| result.push(interval); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return result; | ||
|
|
||
| }; |
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 배열 정렬에 O(n log n) 시간이 소요되고, 이후 순차 검사로 O(n)입니다. 공간은 정렬을 위한 제자리 정렬이 아니면 추가 공간이 필요할 수 있으나, 여기서는 sort의 공간 복잡도 고려. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * @param {number[]} nums | ||
| * @return {number} | ||
| */ | ||
| var missingNumber = function (nums) { | ||
|
|
||
| let n = nums.length + 1; | ||
| let sortedNums = nums.sort((a, b) => a - b); | ||
|
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. sort를 사용하셨군요! 👍 |
||
|
|
||
| for (let i = 0; i < n; i++) { | ||
| if (sortedNums[i] === i) { | ||
| continue; | ||
| } else { | ||
| return i; | ||
| } | ||
| } | ||
| }; | ||
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 배열 정렬에 O(n log n) 시간이 소요되고, 결과 저장을 위해 O(n) 공간이 필요합니다. 반복문은 O(n)입니다.
개선 제안: 현재 구현이 적절해 보입니다.