File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
src/main/java/g3301_3400/s3327_check_if_dfs_strings_are_palindromes Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -26,16 +26,20 @@ private void dfs(int x) {
26
26
r [x ] = ++now ;
27
27
}
28
28
29
- private void manacher () {
29
+ private void matcher () {
30
30
c [0 ] = '~' ;
31
31
c [1 ] = '#' ;
32
32
for (int i = 1 ; i <= n ; ++i ) {
33
33
c [2 * i + 1 ] = '#' ;
34
34
c [2 * i ] = stringBuilder .charAt (i - 1 );
35
35
}
36
36
for (int i = 1 , mid = 0 , r = 0 ; i <= 2 * n + 1 ; ++i ) {
37
- if (i <= r ) p [i ] = Math .min (p [(mid << 1 ) - i ], r - i + 1 );
38
- while (c [i - p [i ]] == c [i + p [i ]]) ++p [i ];
37
+ if (i <= r ) {
38
+ p [i ] = Math .min (p [(mid << 1 ) - i ], r - i + 1 );
39
+ }
40
+ while (c [i - p [i ]] == c [i + p [i ]]) {
41
+ ++p [i ];
42
+ }
39
43
if (p [i ] + i > r ) {
40
44
r = p [i ] + i - 1 ;
41
45
mid = i ;
@@ -57,7 +61,7 @@ public boolean[] findAnswer(int[] parent, String s) {
57
61
dfs (0 );
58
62
c = new char [2 * n + 10 ];
59
63
p = new int [2 * n + 10 ];
60
- manacher ();
64
+ matcher ();
61
65
boolean [] ans = new boolean [n ];
62
66
for (int i = 0 ; i < n ; ++i ) {
63
67
int mid = (2 * r [i ] - 2 * l [i ] + 1 ) / 2 + 2 * l [i ];
You can’t perform that action at this time.
0 commit comments