Skip to content

Commit

Permalink
update post
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-jonghoonpark committed Jul 23, 2024
1 parent b236f82 commit ee3537e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion _posts/2024-02-14-leetcode-57.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public int[][] merge(int[][] intervals) {
문제를 잘 읽어보면 intervals 의 경우 start를 기준으로 이미 정렬이 되어있다고 하였기 떄문에 따로 정렬을 해줄 필요는 없다.
for loop 에서는 start, end pointer를 이용해서 어느 구간이 병합되는지 기억해두고, 최종적으로 병합을 진행한다.

`System.arraycopy` 의 경우에는 ([공식 문서](https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#arraycopy-java.lang.Object-int-java.lang.Object-int-int-)) array의 data를 copy할 때 효율적으로 처리할 수 있지만, api가 직관적이지는 못한 것 같다. 그래도 한 번 적용해보았다.
start 가 -1 인 경우는 맨 오른쪽에 추가가 되어야 한다는 의미이고
end 가 -1 인 경우는 맨 왼쪽에 추가가되어야 한다는 의미이다.
그 외에는 병합이 발생한 것이므로 병합처리를 진행한다.

```java
class Solution {
Expand Down Expand Up @@ -218,3 +220,7 @@ class Solution {
#### TC, SC

시간 복잡도는 `O(n)` 공간 복잡도는 `O(1)` 이다. (결과를 반환하기 위해 생성된 `int[][]`는 고려하지 않는다.)

#### System.arraycopy

`System.arraycopy` 의 경우에는 ([공식 문서](https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#arraycopy-java.lang.Object-int-java.lang.Object-int-int-)) array의 data를 copy할 때 효율적으로 처리할 수 있지만, 개인적으로 api가 직관적이지는 못한 것 같다. 그래도 한 번 적용해보았다.

0 comments on commit ee3537e

Please sign in to comment.