mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 15:01:40 +08:00
国外版
This commit is contained in:
28
算法题(国外版)/longest-happy-prefix.html
Normal file
28
算法题(国外版)/longest-happy-prefix.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<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> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "level"
|
||||
<strong>Output:</strong> "l"
|
||||
<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".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "ababab"
|
||||
<strong>Output:</strong> "abab"
|
||||
<strong>Explanation:</strong> "abab" is the largest prefix which is also suffix. They can overlap in the original string.
|
||||
</pre>
|
||||
|
||||
<p> </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>
|
Reference in New Issue
Block a user