Skip to content

Commit ec0f0b6

Browse files
authoredMar 11, 2024
Update README_EN.md
1 parent 4163925 commit ec0f0b6

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed
 

‎solution/0400-0499/0488.Zuma Game/README_EN.md

+31-32
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ class Solution:
102102
return -1
103103
```
104104

105-
```Java
106-
105+
```java
107106
class Solution {
108107
public int findMinStep(String board, String hand) {
109108
final Zuma zuma = Zuma.create(board, hand);
@@ -116,29 +115,27 @@ class Solution {
116115
}
117116

118117
private int bfs(ArrayList<Zuma> curr, int k, HashSet<Long> visited) {
119-
if (curr.isEmpty())
118+
if (curr.isEmpty()) {
120119
return -1;
120+
}
121121

122122
final ArrayList<Zuma> next = new ArrayList<>();
123123

124124
for (Zuma zuma : curr) {
125125
ArrayList<Zuma> neib = zuma.getNextLevel(k, visited);
126-
if (neib == null)
126+
if (neib == null) {
127127
return k + 1;
128+
}
128129

129130
next.addAll(neib);
130131
}
131132
return bfs(next, k + 1, visited);
132133
}
133134
}
134135

135-
136136
record Zuma(long board, long hand) {
137137
public static Zuma create(String boardStr, String handStr) {
138-
return new Zuma(
139-
Zuma.encode(boardStr, false),
140-
Zuma.encode(handStr, true)
141-
);
138+
return new Zuma(Zuma.encode(boardStr, false), Zuma.encode(handStr, true));
142139
}
143140

144141
public ArrayList<Zuma> getNextLevel(int depth, HashSet<Long> visited) {
@@ -150,15 +147,18 @@ record Zuma(long board, long hand) {
150147
for (long[] pair : handList) {
151148
for (int i = 0; i < size; ++i) {
152149
final long rawBoard = pruningCheck(boardList[i], pair[0], i * 3, depth);
153-
if (rawBoard == -1)
150+
if (rawBoard == -1) {
154151
continue;
152+
}
155153

156154
final long nextBoard = updateBoard(rawBoard);
157-
if (nextBoard == 0)
155+
if (nextBoard == 0) {
158156
return null;
157+
}
159158

160-
if (pair[1] == 0 || visited.contains(nextBoard))
159+
if (pair[1] == 0 || visited.contains(nextBoard)) {
161160
continue;
161+
}
162162

163163
visited.add(nextBoard);
164164
next.add(new Zuma(nextBoard, pair[1]));
@@ -171,8 +171,7 @@ record Zuma(long board, long hand) {
171171
final long L = (insBoard >> (pos + 3)) & 0x7;
172172
final long R = (insBoard >> (pos - 3)) & 0x7;
173173

174-
if (depth == 0 && (ball != R) && (L != R) ||
175-
depth > 0 && (ball != R)) {
174+
if (depth == 0 && (ball != R) && (L != R) || depth > 0 && (ball != R)) {
176175
return -1;
177176
}
178177
return insBoard | (ball << pos);
@@ -183,21 +182,20 @@ record Zuma(long board, long hand) {
183182

184183
for (int i = 0; i < 64; i += 3) {
185184
final long curr = (board >> i) & 0x7;
186-
final long top = (stack) & 0x7;
185+
final long top = (stack) &0x7;
187186

188187
// pop (if possible)
189-
if ((top > 0) && (curr != top) &&
190-
(stack & 0x3F) == ((stack >> 3) & 0x3F))
191-
{
188+
if ((top > 0) && (curr != top) && (stack & 0x3F) == ((stack >> 3) & 0x3F)) {
192189
stack >>= 9;
193-
if ((stack & 0x7) == top)
194-
stack >>= 3;
190+
if ((stack & 0x7) == top) stack >>= 3;
195191
}
196192

197-
if (curr == 0)
198-
break; // done
199-
else
200-
stack = (stack << 3) | curr; // push and continue
193+
if (curr == 0) {
194+
// done
195+
break;
196+
}
197+
// push and continue
198+
stack = (stack << 3) | curr;
201199
}
202200
return stack;
203201
}
@@ -209,15 +207,14 @@ record Zuma(long board, long hand) {
209207

210208
for (int i = 0; i < 16; i += 3) {
211209
final long currBall = (this.hand >> i) & 0x7;
212-
if (currBall == 0)
210+
if (currBall == 0) {
213211
break;
212+
}
214213

215214
if (currBall != prevBall) {
216215
prevBall = currBall;
217-
handList.add(new long[]{
218-
currBall,
219-
((this.hand >> 3) & ~ballMask) | (this.hand & ballMask)
220-
});
216+
handList.add(
217+
new long[] {currBall, ((this.hand >> 3) & ~ballMask) | (this.hand & ballMask)});
221218
}
222219
ballMask = (ballMask << 3) | 0x7;
223220
}
@@ -232,8 +229,9 @@ record Zuma(long board, long hand) {
232229

233230
while (true) {
234231
final long currBall = this.board & ballMask;
235-
if (currBall == 0)
232+
if (currBall == 0) {
236233
break;
234+
}
237235

238236
ballMask <<= 3;
239237
insBoard = (insBoard | currBall) & ~ballMask;
@@ -244,8 +242,9 @@ record Zuma(long board, long hand) {
244242

245243
private static long encode(String stateStr, boolean sortFlag) {
246244
final char[] stateChars = stateStr.toCharArray();
247-
if (sortFlag)
245+
if (sortFlag) {
248246
Arrays.sort(stateChars);
247+
}
249248

250249
long stateBits = 0;
251250
for (char ch : stateChars) {
@@ -255,7 +254,7 @@ record Zuma(long board, long hand) {
255254
}
256255

257256
private static long encode(char ch) {
258-
return switch(ch) {
257+
return switch (ch) {
259258
case 'R' -> 0x1;
260259
case 'G' -> 0x2;
261260
case 'B' -> 0x3;

0 commit comments

Comments
 (0)