Skip to content

Commit

Permalink
add post '(Leetcode) 48 - Rotate Image 풀이'
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-jonghoonpark committed Jul 22, 2024
1 parent 1873814 commit 1a3b442
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _posts/2024-07-22-leetcode-253.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: post
title: (Leetcode) 253 - Meeting Room ii 풀이 (Meeting Schedule ii)
title: (Leetcode) 253 - Meeting Room ii 풀이 (Meeting Schedule ii)
categories: [스터디-알고리즘]
tags: [자바, java, 리트코드, Leetcode, 알고리즘, interval, array, sorting]
date: 2024-07-22 19:30:00 +0900
Expand Down
44 changes: 44 additions & 0 deletions _posts/2024-07-22-leetcode-48.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
layout: post
title: (Leetcode) 48 - Rotate Image 풀이
categories: [스터디-알고리즘]
tags: [자바, java, 리트코드, Leetcode, 알고리즘, array, matrix]
date: 2024-07-22 16:30:00 +0900
toc: true
---

기회가 되어 [달레님의 스터디](https://github.com/DaleStudy/leetcode-study)에 참여하여 시간이 될 때마다 한문제씩 풀어보고 있다.

[https://neetcode.io/practice](https://neetcode.io/practice)

---

[https://leetcode.com/problems/rotate-image/description/](https://leetcode.com/problems/rotate-image/description/)

## 내가 작성한 풀이

rotate 가 진행될 때 어떤 아이템이 어디로 이동되는지 확인하고 그것을 일반화해서 해결하였다.
실제 배열과 수학 행렬을 매칭시켜주는게 다소 헷갈리기 때문에 변수와 위치 정의를 잘 해두면 좋을 것 같다.

```java
class Solution {
public void rotate(int[][] matrix) {
int l = matrix.length;

int limit = (int) Math.ceil((double) l / 2);
for (int i = 0; i < limit; i++) {
for (int j = i; j < l - 1 - i; j++) {
int temp = matrix[i][j];
matrix[i][j] = matrix[l - j - 1][i];
matrix[l - j - 1][i] = matrix[l - i - 1][l - j - 1];
matrix[l - i - 1][l - j - 1] = matrix[j][l - i - 1];
matrix[j][l - i - 1] = temp;
}
}
}
}
```

### TC, SC

시간 복잡도는 `O(n^2)` 공간 복잡도는 `O(1)` 이다.
2 changes: 1 addition & 1 deletion _posts/2024-07-23-leetcode-435.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: post
title: (Leetcode) 435 - Non-overlapping Intervals 풀이
title: (Leetcode) 435 - Non-overlapping Intervals 풀이
categories: [스터디-알고리즘]
tags:
[자바, java, 리트코드, Leetcode, 알고리즘, interval, array, greedy, sorting]
Expand Down

0 comments on commit 1a3b442

Please sign in to comment.