• 문제 링크
Image Smoother - LeetCode
Can you solve this real interview question? Image Smoother - An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nin
leetcode.com
• 풀이 코드
public class Solution {
public int[][] imageSmoother(int[][] img) {
int n = img.length, m = img[0].length;
int[][] mat = new int[n][m];
for (int r = 0; r < n; r++) {
for (int c = 0; c < m; c++) {
int sum = 0, cnt = 0;
for (int i = r - 1; i <= r + 1; i++) {
for (int j = c - 1; j <= c + 1; j++) {
if (i < 0 || i >= n || j < 0 || j >= m) continue;
sum += img[i][j];
cnt++;
}
}
mat[r][c] = sum / cnt;
}
}
return mat;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 674. Longest Continuous Increasing Subsequence - Java (0) | 2026.09.21 |
|---|---|
| [LeetCode] 671. Second Minimum Node In a Binary Tree - Java (0) | 2026.09.20 |
| [LeetCode] 657. Robot Return to Origin - Java (0) | 2026.09.18 |
| [LeetCode] 653. Two Sum IV - Input is a BST - Java (0) | 2026.09.17 |
| [LeetCode] 645. Set Mismatch - Java (0) | 2026.09.16 |
댓글