Class Solution
java.lang.Object
g1301_1400.s1392_longest_happy_prefix.Solution
1392 - Longest Happy Prefix.<p>Hard</p>
<p>A string is called a <strong>happy prefix</strong> if is a <strong>non-empty</strong> prefix which is also a suffix (excluding itself).</p>
<p>Given a string <code>s</code>, return <em>the <strong>longest happy prefix</strong> of</em> <code>s</code>. Return an empty string <code>""</code> if no such prefix exists.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “level”</p>
<p><strong>Output:</strong> “l”</p>
<p><strong>Explanation:</strong> 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”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “ababab”</p>
<p><strong>Output:</strong> “abab”</p>
<p><strong>Explanation:</strong> “abab” is the largest prefix which is also suffix. They can overlap in the original string.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
<li><code>s</code> contains only lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
longestPrefix
-