Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int commonCharacterCount(string s1, string s2)
- {
- if (String.IsNullOrEmpty(s1) || String.IsNullOrEmpty(s2))
- return 0;
- int[,] num = new int[s1.Length, s2.Length];
- int maxlen = 0;
- for (int i = 0; i < s1.Length; i++)
- {
- for (int j = 0; j < s2.Length; j++)
- {
- if (s1[i] != s2[j])
- num[i, j] = 0;
- else
- {
- if ((i == 0) || (j == 0))
- num[i, j] = 1;
- else
- num[i, j] = 1 + num[i - 1, j - 1];
- if (num[i, j] > maxlen)
- {
- maxlen = num[i, j];
- }
- }
- }
- }
- return maxlen;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement