@@ -79,19 +79,21 @@ static String print(int r, int c) {
79
79
80
80
static void unmerge (int r , int c ) {
81
81
int key = markGroupNum [r ][c ];
82
+ String value = table [r ][c ];
82
83
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 ();
93
85
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 ;
95
97
}
96
98
97
99
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) {
121
123
static void update (String value1 , String value2 ) {
122
124
for (int r = 1 ; r < table .length ; r ++) {
123
125
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 ;
129
128
}
130
129
}
131
130
}
0 commit comments