-
-
Notifications
You must be signed in to change notification settings - Fork 361
[Yiseull] WEEK 11 Solutions #2853
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
|
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. 저는 정답 배열을 선언했는데, intervals 배열을 인플레이스로 수정한 후에 슬라이스하셨군요
Contributor
Author
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. 네넹! okyungjin님 리뷰 달 때 안그래도 인플레이스 방법 말씀드리려다가 말았었는데, 클로드 말로는 자바에서 인플레이스가 의미 있었던 건 ArrayList 증설 + 구간마다 clone() + toArray 복사가 한꺼번에 사라졌기 때문인데, 파이썬은 없어지는 게 리스트 객체 하나와 append 호출뿐이라 자바만큼에 큰 이득은 아니라고 하더라구요! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| class Solution { | ||
| public int[][] merge(int[][] intervals) { | ||
| Arrays.sort(intervals, (o1, o2) -> o1[0] - o2[0]); | ||
|
|
||
| int index = 0; | ||
| for (int i = 0; i < intervals.length; i++) { | ||
| if (intervals[index][1] < intervals[i][0]) { | ||
| intervals[++index] = intervals[i]; | ||
| } else { | ||
| intervals[index][1] = Math.max(intervals[index][1], intervals[i][1]); | ||
| } | ||
| } | ||
|
|
||
| return Arrays.copyOf(intervals, index + 1); | ||
| } | ||
| } |
|
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. 🏷️ 알고리즘 패턴 분석missing-number/Yiseull.javaclass Solution {
public int missingNumber(int[] nums) {
int n = nums.length;
int expectedSum = n * (n + 1) / 2;
int actualSum = 0;
for (int num : nums) {
actualSum += num;
}
return expectedSum - actualSum;
}
}
📊 시간/공간 복잡도 분석
피드백: 배열의 모든 원소를 한 번 순회하며 합을 구하고, 가용한 산술로 누락된 숫자를 계산합니다. 개선 제안: 현재 구현이 적절해 보입니다.
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. 파이썬에는 sum 함수가 있어서 찾아보니 자바에서는 아래와 같이 작성할 수 있는 것 같습니다! Arrays.stream(nums).sum();
Contributor
Author
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. 자바에서 for문이랑 stream이랑 약간의 성능이랑 동작 차이가 있는데, 저는 이 풀이에서는 그런것까진 따지지 않고 for문을 쓰긴 했어요 ㅎ 클로드한테 물어보니 아래일 때 어떤 걸 선택하는게 좋은지 정리해주네요~!
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class Solution { | ||
| public int missingNumber(int[] nums) { | ||
| int n = nums.length; | ||
| int expectedSum = n * (n + 1) / 2; | ||
| int actualSum = 0; | ||
|
|
||
| for (int num : nums) { | ||
| actualSum += num; | ||
| } | ||
|
|
||
| return expectedSum - actualSum; | ||
| } | ||
| } |
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.
🏷️ 알고리즘 패턴 분석
merge-intervals/Yiseull.java
📊 시간/공간 복잡도 분석
피드백: 입력 구간을 시작점 기준으로 정렬한 뒤, 현재 구간과 다음 구간의 관계를 검사하며 필요 시 합치는 방식으로 한 번의 순회로 최종 구간들을 얻습니다.
개선 제안: 현재 구현이 적절해 보입니다.