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
- two pointers
- Number Theory
- Binary Search
- Binary Tree
- Math
- Matrix
- 구현
- Stack
- 코딩테스트
- bit manipulation
- Tree
- 코테
- string
- geometry
- Data Structure
- 파이썬
- dynamic programming
- SQL
- hash table
- Method
- 자바
- implement
- Class
- greedy
- Counting
- java
- simulation
- sorting
- array
- database
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 832. Flipping an Image 본문
1. Input
1) 크기가 n*n인 2차원 행렬 image
2. Output
1) 각 행의 요소를 거꾸로 배열(flipping)한 뒤 0을 1로, 1을 0으로 변환(invert)한 행렬
3. Constraint
1) n == image.length == image[i].length
2) 1 <= n <= 20
3) images[i][j]는 0 또는 1이다.
4. Example
Input: image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]] -> Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
설명:
- 처음에 각 행의 요소를 거꾸로 하면 [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]이 된다.
- 그 후 0을 1로, 1을 0으로 바꾸면 [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]이 된다.
5. Code
1) 첫 코드(2022/06/14)
int n = image.length;
int tmp = 0;
for(int i=0 ; i<n ; i++){
for(int j=0 ; j<n/2 ; j++){
tmp = image[i][j]==0 ? 1 : 0;
image[i][j] = image[i][n-1-j]==0 ? 1 : 0;
image[i][n-1-j] = tmp;
} // for j
} // for i
if(n%2 != 0){
for(int i=0 ; i<n ; i++){
image[i][n/2] = image[i][n/2]==0 ? 1 : 0;
} // for i
}
return image;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 867. Transpose Matrix (0) | 2022.12.08 |
---|---|
[LeetCode/Easy] 860. Lemonade Change (0) | 2022.12.08 |
[LeetCode/Easy] 824. Goat Latin (0) | 2022.12.08 |
[LeetCode/Easy] 821. Shortest Distance to a Character (0) | 2022.12.08 |
[LeetCode/Easy] 806. Number of Lines To Write String (0) | 2022.12.07 |