Adrian Kuegel wrote:It is possible to solve this problem in O(n).
Could anyone please give me more hint ?
I don't know how to do it in O(n)
Moderator: Board moderators
Hi javier lira,
You can try a case with aaaaa.....(repeat 10000 times)
or try a case with aaaaa...(5000 times)...bbbbb...(5000 times).
Remember that you don't need to scan from left to right for the start point with step 1 always.
If there are matches more than one characters, you can move to next start point with more steps.
@ double the string -> str[] = "String""String"
@ i=0 j=1 k=0 len=str.length()
while(i<len && j<len)
# if(str[i+k] == str[j+k]) { k++; if(k==len) break; }
# if(str[i+k] > str[j+k]) { i=i+k+1; if(i<=j) i=j+1; k=0; }
# if(str[i+k] < str[j+k]) { j=j+k+1; if(j<=i) j=i+1; k=0; }
return Min(i,j)
suneast wrote:hi , all :
I think I have a better O(N) solution using an Algorithm by "周源(ZhouYuan)" called "最小表示法(Minimum Expression)" in Chinese..![]()
A simple code using O(N)time above will solve the problem![]()
if U want to know more details about the algorithm, you can search the Internet using keyword "周源 最小表示法" (in Chinese)
Hope I'm help to you all
Users browsing this forum: No registered users and 0 guests