반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- JSX
- bit
- 비트연산
- node.js
- DP
- component
- leetcode
- count
- map
- css
- Context
- treenode
- Callback
- UE5
- queue
- state
- React
- MySQL
- BinaryTree
- Props
- route
- Navigation
- nodeJS
- priority_queue
- server
- routes
- event
- axios
- array
- c++
Archives
- Today
- Total
우사미 코딩
[Leetcode] 48. Rotate Image - Matrix 본문
반응형
1. 문제링크
Rotate Image - LeetCode
Can you solve this real interview question? Rotate Image - You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place [https://en.wikipedia.org/wiki/In-place_algorithm], which m
leetcode.com
2. 매트릭스 변환 2회
1) mat[i][j] <-> mat[j][i]
1 2 3 1 4 7
4 5 6 -> 2 5 8
7 8 9 3 6 9
2) 각 row를 revers
1 4 7 7 4 1
2 5 8 -> 8 5 2
3 6 9 9 6 3
3. solution
class Solution {
public:
void rotate(vector<vector<int>>& mat) {
int n = mat.size();
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
swap(mat[i][j], mat[j][i]);
}
}
for(int i = 0; i < n; i++){
reverse(mat[i].begin(), mat[i].end());
}
}
};
반응형
'Leetcode' 카테고리의 다른 글
| [Leetcode] 953. Verifying an Alien Dictionary - hash map (0) | 2023.05.22 |
|---|---|
| [Leetcode] 148. Sort List (0) | 2023.05.19 |
| [Leetcode] 15. 3Sum - two pointers를 사용하자 (0) | 2023.05.18 |
| [Leetcode] 153. Find Minimum in Rotated Sorted Array - 주옥같은 binary search (0) | 2023.05.17 |
| [LeetCode] 202. Happy Number - 주옥같은 해피넘버 (0) | 2023.05.17 |
Comments