Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4f95646

Browse files
committed
고다혜: [PG] 150366 표 병합_241114
1 parent 6d3b20d commit 4f95646

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

‎Programmers/Level3/DH_150366.java‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,21 @@ static String print(int r, int c) {
7979

8080
static void unmerge(int r, int c) {
8181
int key = markGroupNum[r][c];
82+
String value = table[r][c];
8283

83-
ArrayList<Point> removeSet = new ArrayList<Point>();
84-
for(Point p: hashMap.get(key)) {
85-
if(p.r == r && p.c == c) continue;
86-
87-
int nextKey = p.r * 51 + p.c;
88-
markGroupNum[p.r][p.c] = nextKey;
89-
table[p.r][p.c] = null;
90-
removeSet.add(p);
91-
hashMap.get(nextKey).add(p);
92-
}
84+
hashMap.get(key).clear();
9385

94-
hashMap.get(key).removeAll(removeSet);
86+
for(int rr = 1; rr < table.length; rr++) {
87+
for(int cc = 1; cc < table[0].length; cc++) {
88+
if(markGroupNum[rr][cc] == key) {
89+
int realKey = rr * 51 + cc;
90+
table[rr][cc] = null;
91+
markGroupNum[rr][cc] = realKey;
92+
hashMap.get(realKey).add(new Point(rr, cc));
93+
}
94+
}
95+
}
96+
table[r][c] = value;
9597
}
9698

9799
static void merge(int r1, int c1, int r2, int c2) {
@@ -121,11 +123,8 @@ static void merge(int r1, int c1, int r2, int c2) {
121123
static void update(String value1, String value2) {
122124
for(int r = 1; r < table.length; r++) {
123125
for(int c = 1; c < table[0].length; c++) {
124-
if(table[r][c] == null || !table[r][c].equals(value1)) continue;
125-
126-
int key = markGroupNum[r][c];
127-
128-
for(Point p: hashMap.get(key)) table[p.r][p.c] = value2;
126+
if(table[r][c] != null && table[r][c].equals(value1))
127+
table[r][c] = value2;
129128
}
130129
}
131130
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /