Skip to content

Commit 41aa4de

Browse files
committed
Runtime: 911 ms (Top 7.06%) | Memory: 70.7 MB (Top 63.53%)
1 parent c040614 commit 41aa4de

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 911 ms (Top 7.06%) | Memory: 70.7 MB (Top 63.53%)
12
class Solution {
23
int TIME_MAX = 200;
34
int DRAW = 0;
@@ -9,10 +10,10 @@ public int catMouseGame(int[][] graph) {
910

1011
private int dfs(int time, int[] p, int[][] graph, Integer[][][] memo){ // p[0] -> mouse position, p[1] -> cat position
1112
Integer old = memo[time][p[0]][p[1]];
12-
if (old != null) return old; // all the base cases here
13+
if (old != null) return old; // all the base cases here
1314
if (time >= TIME_MAX) return DRAW;
14-
if (p[0]==0) return MOUSE_WIN;
15-
if (p[0]==p[1]) return CAT_WIN;
15+
if (p[0]==0) return MOUSE_WIN;
16+
if (p[0]==p[1]) return CAT_WIN;
1617
int state = 0;
1718
int where = p[time&1];
1819
int res = DRAW;
@@ -21,15 +22,15 @@ private int dfs(int time, int[] p, int[][] graph, Integer[][][] memo){ // p[0] -
2122
p[time&1]=graph[where][i];
2223
state |= 1 << dfs(time+1, p, graph, memo);
2324
if ((time&1)>0&&(state&4)>0 || (time&1)==0&&(state&2)>0) // if mouse's turn & mouse win
24-
break; // or cat's turn & cat win, then we stop.
25+
break; // or cat's turn & cat win, then we stop.
2526
}
2627
}
2728
p[time&1]=where; // restore p
28-
if (((time&1)>0 && (state & 4)>0)||((time&1)==0) && state==4){
29+
if (((time&1)>0 && (state & 4)>0)||((time&1)==0) && state==4){
2930
res = CAT_WIN; // cat win when (cat's turn & cat win) or (mouse's turn and state = cat)
3031
}else if (((time&1)==0 && (state & 2)>0)||(time&1)==1 && state==2){
3132
res = MOUSE_WIN; // mouse win when (mouse's turn and mouse win) or (cat's turn and state = mouse)
3233
}
3334
return memo[time][p[0]][p[1]]=res;
3435
}
35-
}
36+
}

0 commit comments

Comments
 (0)