Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions rotate-image/DaleSeo.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Transpose, Reverse
  • 설명: 이 코드는 행렬을 대각선 기준으로 전치시키고 각 행을 뒤집는 방식으로 회전시키며, 이는 행렬 변환의 대표적인 패턴입니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n^2) O(n^2)
Space O(1) O(1)

피드백: 행렬의 크기 n에 대해 두 번의 반복문이 각각 O(n^2) 수행되어 전체 시간 복잡도는 O(n^2)이다. 공간은 입력 행렬을 제자리에서 수정하므로 O(1)이다.

개선 제안: 현재 구현이 적절해 보입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TC: O(n^2)
// SC: O(1)
impl Solution {
pub fn rotate(matrix: &mut Vec<Vec<i32>>) {
let n = matrix.len();

for i in 0..n {
for j in (i + 1)..n {
let tmp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = tmp;
}
}

for row in matrix.iter_mut() {
row.reverse();
}
}
}
Loading