问题定义不明确 最长公共前缀
problem definition not clear Longest common prefix
问题陈述:
在一次采访中,我遇到了一个我无法弄明白的问题的编码挑战。
Given a string s contains lowercase alphabet, find the length of the Longest common Prefix of all substrings in O(n)
For example
s = 'ababac'
Then substrings are as follow:
1: s(1, 6) = ababac
2: s(2, 6) = babac
3: s(3, 6) = abac
4: s(4, 6) = bac
5: s(5, 6) = ac
6: s(6, 6) = c
Now, The lengths of LCP of all substrings are as follow
1: len(LCP(s(1, 6), s)) = 6
2: len(LCP(s(2, 6), s)) = 0
3: len(LCP(s(3, 6), s)) = 3
4: len(LCP(s(4, 6), s)) = 0
5: len(LCP(s(5, 6), s)) = 1
6: len(LCP(s(6, 6), s)) = 0
String contains only lowercase alphabates.
我在这个社区发现了一些相同的问题,但它们只是问题陈述,含义无法定义。
This one
其中一个 leetcode 问题也有点像我完全理解的问题和代码:Longest common prefix 但是我的问题听起来一样,但主要区别在于所有此类问题都提供了一个字符串数组,但是在我的问题是只有一个字符串,我必须从这个字符串中找出最长的公共前缀。
任何人都可以正确地向我解释这个问题到底在找什么吗?
你需要找到两个字符串之间最长的公共子串。在每种情况下,其中之一是原始字符串 s
。另一个字符串是 s
的右端子字符串。这些是第一个列表。
举几个例子:
substring common len reason
s(1, 6) = ababac ababac 6 Comparing the string with itself yields the entire string
s(3, 6) = abac aba 3 Only the first 3 characters match
s(4, 6) = bac -none- 0 The first characters differ, so there is no common prefix.
有帮助吗?
问题陈述: 在一次采访中,我遇到了一个我无法弄明白的问题的编码挑战。
Given a string s contains lowercase alphabet, find the length of the Longest common Prefix of all substrings in O(n)
For example
s = 'ababac'
Then substrings are as follow:
1: s(1, 6) = ababac
2: s(2, 6) = babac
3: s(3, 6) = abac
4: s(4, 6) = bac
5: s(5, 6) = ac
6: s(6, 6) = c
Now, The lengths of LCP of all substrings are as follow
1: len(LCP(s(1, 6), s)) = 6
2: len(LCP(s(2, 6), s)) = 0
3: len(LCP(s(3, 6), s)) = 3
4: len(LCP(s(4, 6), s)) = 0
5: len(LCP(s(5, 6), s)) = 1
6: len(LCP(s(6, 6), s)) = 0
String contains only lowercase alphabates.
我在这个社区发现了一些相同的问题,但它们只是问题陈述,含义无法定义。 This one
其中一个 leetcode 问题也有点像我完全理解的问题和代码:Longest common prefix 但是我的问题听起来一样,但主要区别在于所有此类问题都提供了一个字符串数组,但是在我的问题是只有一个字符串,我必须从这个字符串中找出最长的公共前缀。
任何人都可以正确地向我解释这个问题到底在找什么吗?
你需要找到两个字符串之间最长的公共子串。在每种情况下,其中之一是原始字符串 s
。另一个字符串是 s
的右端子字符串。这些是第一个列表。
举几个例子:
substring common len reason
s(1, 6) = ababac ababac 6 Comparing the string with itself yields the entire string
s(3, 6) = abac aba 3 Only the first 3 characters match
s(4, 6) = bac -none- 0 The first characters differ, so there is no common prefix.
有帮助吗?