Musings
Public · Protected · Private
Longest common substring
-
2008-07-15 11:26Given two strings find the longest common substring -- If more than two common substring? -- return the first occuring one (of first string??/other?)
-
2008-07-15 11:30private string findthecommon(string string1, string string2) { string answer = ""; //Start char i for (int i = 0; i < string1.Length; i++) { // end char j for (int j = i+1; j < (string1.Length +1); j++) { if (answer.Length < (j - i)) { string tocompare = string1.Substring(i, j - i); if (string2.IndexOf(tocompare) >= 0) { //if (answer.Length < tocompare.Length) answer = tocompare; } } } } return answer ; }
-
2008-07-15 15:31tested code है क्या?
-
2008-07-16 17:57This is not an optimal code,What is the complexityof this solution? We can try using more basic 2 dimensional arrays.
This blog is frozen. No new comments or edits allowed.