Public · Protected · Private
Longest common substring
Type: Public  |  Created: 2008-07-15  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • Given 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:26
  • private 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 11:30
  • tested code है क्या?
    2008-07-15 15:31
  • This is not an optimal code,What is the complexityof this solution? We can try using more basic 2 dimensional arrays.
    2008-07-16 17:57
This blog is frozen. No new comments or edits allowed.