From d20c0a014b2fb7524c0bb3254ee9cabeea1069be Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sun, 28 Jul 2019 06:26:12 +0100 Subject: - Added solutions by guest Orestis Zekai. --- challenge-018/orestis-zekai/python/ch-1.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 challenge-018/orestis-zekai/python/ch-1.py (limited to 'challenge-018/orestis-zekai/python/ch-1.py') diff --git a/challenge-018/orestis-zekai/python/ch-1.py b/challenge-018/orestis-zekai/python/ch-1.py new file mode 100644 index 0000000000..e997db9e74 --- /dev/null +++ b/challenge-018/orestis-zekai/python/ch-1.py @@ -0,0 +1,18 @@ +# Longest common substring + +string1 = "ABABC" +string2 = "BABCA" + +max_substring = "" +max_length = -1 + + +for i in range(0, len(string1)+1): + for j in range(0, len(string1)+1): + if (string1[i:j] in string2) and len(string1[i:j]) > max_length: + max_length = len(string1[i:j]) + max_substring = string1[i:j] + + +print('The longest substring is: ' + max_substring) +print('The length of the longest substring is: ' + str(max_length)) \ No newline at end of file -- cgit