Class Solution
java.lang.Object
g1301_1400.s1392_longest_happy_prefix.Solution
public class Solution
extends java.lang.Object
1392 - Longest Happy Prefix.
Hard
A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).
Given a string s
, return the longest happy prefix of s
. Return an empty string ""
if no such prefix exists.
Example 1:
Input: s = βlevelβ
Output: βlβ
Explanation: s contains 4 prefix excluding itself (βlβ, βleβ, βlevβ, βleveβ), and suffix (βlβ, βelβ, βvelβ, βevelβ). The largest prefix which is also suffix is given by βlβ.
Example 2:
Input: s = βabababβ
Output: βababβ
Explanation: βababβ is the largest prefix which is also suffix. They can overlap in the original string.
Constraints:
1 <= s.length <= 105
s
contains only lowercase English letters.
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
longestPrefix
public java.lang.String longestPrefix(java.lang.String s)
-