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
- 코테
- bit manipulation
- Binary Search
- 자바
- Tree
- Binary Tree
- Counting
- java
- implement
- Stack
- string
- sorting
- Method
- 코딩테스트
- database
- greedy
- Matrix
- dynamic programming
- two pointers
- Number Theory
- geometry
- Class
- simulation
- Data Structure
- array
- 파이썬
- SQL
- hash table
- 구현
- Math
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 883. Projection Area of 3D Shapes 본문
1. Input
1) 크기가 n*n인 2차원 int 행렬 grid
2) grid[i][j]는 (i, j)에 쌓여있는 큐브의 수
2. Output
1) xy평면, yz평면, zx평면에 보이는 큐브의 수의 합
3. Constraint
1) n == grid.length == grid[i].length
2) 1 <= n <= 50
3) 0 <= grid[i][j] <= 50
4. Example
Input: grid = [[1,2],[3,4]] -> Output: 17
5. Code
1) 첫 코드(2022/07/26)
int m = grid.length;
int n = grid[0].length;
int xy=0, yz=0, zx=0;
for(int i=0 ; i<m ; i++)
for(int j=0 ; j<n ; j++)
if(grid[i][j]!=0)
xy++;
for(int i=0 ; i<m ; i++){
int max = 0;
for(int j=0 ; j<n ; j++)
if(grid[i][j]>max)
max = grid[i][j];
zx += max;
}
for(int i=0 ; i<n ; i++){
int max = 0;
for(int j=0 ; j<m ; j++)
if(grid[j][i]>max)
max = grid[j][i];
yz += max;
}
return xy+yz+zx;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 905. Sort Array By Parity (0) | 2022.12.10 |
---|---|
[LeetCode/Easy] 896. Monotonic Array (0) | 2022.12.10 |
[LeetCode/Easy] 867. Transpose Matrix (0) | 2022.12.08 |
[LeetCode/Easy] 860. Lemonade Change (0) | 2022.12.08 |
[LeetCode/Easy] 832. Flipping an Image (0) | 2022.12.08 |