티스토리 뷰
https://leetcode.com/problems/rotate-image/
Rotate Image - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
NxN의 크기를 가진 2차원 배열을 시계방향으로 한번 회전 시키는 문제이다.
impl Solution {
pub fn rotate(mut matrix: &mut Vec<Vec<i32>>) {
let mut v : Vec<Vec<i32>> = matrix.clone();
let n = matrix.len();
for i in 0..n{
for j in 0..n{
matrix[i][n - 1 - j] = v[j][i];
}
}
}
}
2차원 배열을 복사한 뒤 각 위치별로 재정립 하면 된다.
0,0 -> 0, v.length
0,1 -> 1, v.length
.
.
.
n,n -> v.length, 0
요런식으로 완성 시키면 된다.
'알고리즘 문제 풀이' 카테고리의 다른 글
[알고리즘문제] 릿코드 Count of Matches in Tournament (0) | 2021.05.29 |
---|---|
[알고리즘문제] 릿코드 Count and Say (0) | 2021.05.29 |
[알고리즘문제] 릿코드 Climbing Stairs (0) | 2021.05.19 |
[알고리즘문제] 릿코드 Best Time to Buy and Sell Stock(시간초과, brute force) (0) | 2021.05.18 |
[알고리즘문제] 릿코드 Is Subsequence (0) | 2021.05.18 |