Skip to content

Commit 1a3b442

Browse files
add post '(Leetcode) 48 - Rotate Image 풀이'
1 parent 1873814 commit 1a3b442

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

_posts/2024-07-22-leetcode-253.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: (Leetcode) 253 - Meeting Room ii 풀이 (Meeting Schedule ii)
3+
title: (Leetcode) 253 - Meeting Room ii 풀이 (Meeting Schedule ii)
44
categories: [스터디-알고리즘]
55
tags: [자바, java, 리트코드, Leetcode, 알고리즘, interval, array, sorting]
66
date: 2024-07-22 19:30:00 +0900

_posts/2024-07-22-leetcode-48.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
layout: post
3+
title: (Leetcode) 48 - Rotate Image 풀이
4+
categories: [스터디-알고리즘]
5+
tags: [자바, java, 리트코드, Leetcode, 알고리즘, array, matrix]
6+
date: 2024-07-22 16:30:00 +0900
7+
toc: true
8+
---
9+
10+
기회가 되어 [달레님의 스터디](https://github.com/DaleStudy/leetcode-study)에 참여하여 시간이 될 때마다 한문제씩 풀어보고 있다.
11+
12+
[https://neetcode.io/practice](https://neetcode.io/practice)
13+
14+
---
15+
16+
[https://leetcode.com/problems/rotate-image/description/](https://leetcode.com/problems/rotate-image/description/)
17+
18+
## 내가 작성한 풀이
19+
20+
rotate 가 진행될 때 어떤 아이템이 어디로 이동되는지 확인하고 그것을 일반화해서 해결하였다.
21+
실제 배열과 수학 행렬을 매칭시켜주는게 다소 헷갈리기 때문에 변수와 위치 정의를 잘 해두면 좋을 것 같다.
22+
23+
```java
24+
class Solution {
25+
public void rotate(int[][] matrix) {
26+
int l = matrix.length;
27+
28+
int limit = (int) Math.ceil((double) l / 2);
29+
for (int i = 0; i < limit; i++) {
30+
for (int j = i; j < l - 1 - i; j++) {
31+
int temp = matrix[i][j];
32+
matrix[i][j] = matrix[l - j - 1][i];
33+
matrix[l - j - 1][i] = matrix[l - i - 1][l - j - 1];
34+
matrix[l - i - 1][l - j - 1] = matrix[j][l - i - 1];
35+
matrix[j][l - i - 1] = temp;
36+
}
37+
}
38+
}
39+
}
40+
```
41+
42+
### TC, SC
43+
44+
시간 복잡도는 `O(n^2)` 공간 복잡도는 `O(1)` 이다.

_posts/2024-07-23-leetcode-435.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: (Leetcode) 435 - Non-overlapping Intervals 풀이
3+
title: (Leetcode) 435 - Non-overlapping Intervals 풀이
44
categories: [스터디-알고리즘]
55
tags:
66
[자바, java, 리트코드, Leetcode, 알고리즘, interval, array, greedy, sorting]

0 commit comments

Comments
 (0)