1392. Longest Happy Prefix Hard
1/**
2 * [1392] Longest Happy Prefix
3 *
4 * A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).
5 * Given a string s, return the longest happy prefix of s. Return an empty string "" if no such prefix exists.
6 *
7 * Example 1:
8 *
9 * Input: s = "level"
10 * Output: "l"
11 * 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".
12 *
13 * Example 2:
14 *
15 * Input: s = "ababab"
16 * Output: "abab"
17 * Explanation: "abab" is the largest prefix which is also suffix. They can overlap in the original string.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= s.length <= 10^5
23 * s contains only lowercase English letters.
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/longest-happy-prefix/
29// discuss: https://leetcode.com/problems/longest-happy-prefix/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn longest_prefix(s: String) -> String {
35 String::new()
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_1392() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.