Skip to content

Commit 48aaa79

Browse files
authored
Update 1392-longest-happy-prefix.js
1 parent c800c61 commit 48aaa79

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

1392-longest-happy-prefix.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ const longestPrefix = function(s) {
99
let j = 0
1010
const len = s.length
1111
const prefix = Array(len + 1).fill(0)
12+
prefix[0] = -1
13+
prefix[1] = 0
1214
while(i < len) {
1315
if(s[j] === s[i]) {
1416
j++
1517
i++
1618
prefix[i] = j
1719
} else {
1820
if(j > 0) j = prefix[j]
19-
else {
20-
i++
21-
prefix[i] = 0
22-
}
21+
else i++
2322
}
2423
}
2524
return prefix

0 commit comments

Comments
 (0)