Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions leetcode3/염혜정/1034. Coloring A Border.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// dfs

class Solution {

boolean[][] isVisited;
int[] dr = {-1, 1, 0, 0};
int[] dc = {0, 0, -1, 1};

public int[][] colorBorder(int[][] grid, int row, int col, int color) {
isVisited = new boolean[grid.length][grid[0].length];

List<int[]> borders = new ArrayList<>();
dfs (grid, row, col, grid[row][col], borders);

for (int[] b : borders) {
grid[b[0]][b[1]] = color;
}

return grid;
}

void dfs(int[][] grid, int row, int col, int gridColor, List<int[]> borders) {
isVisited[row][col] = true;

boolean isBorder = false;
for (int i = 0; i<4; i++) {
int nr = row + dr[i];
int nc = col + dc[i];

if (nr<0 || nr>=grid.length || nc<0 || nc>=grid[0].length) { // 테두리
isBorder = true;
continue;
}

if (grid[nr][nc] != gridColor) {
isBorder = true;
continue;
}

if (!isVisited[nr][nc]) {
dfs(grid, nr, nc, gridColor, borders);
}
}
if (isBorder) borders.add(new int[]{row, col});
}
}
17 changes: 17 additions & 0 deletions leetcode3/염혜정/3838. Weighted Word Mapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 97 ~ 122

class Solution {
public String mapWordWeights(String[] words, int[] weights) {
StringBuilder sb = new StringBuilder();
for (String word : words) {
int sum = 0;
for (char c : word.toCharArray()) {
int num = (int) c - 97;
sum += weights[num];
}
int mod = sum % 26;
sb.append((char)('z' - mod));
}
return sb.toString();
}
}
11 changes: 11 additions & 0 deletions leetcode3/염혜정/3978. Unique Middle Element.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {
public boolean isMiddleElementUnique(int[] nums) {
int middle = (nums.length - 1) / 2;
int cnt = 0;
for (int num : nums) {
if (num == nums[middle]) cnt++;
if (cnt == 2) break;
}
return cnt == 1;
}
}