Libraryless. Click here for Pure Java version (3808L/22K).
1 | static S longestCommonSubstring(S s1, S s2) { |
2 | int Start = 0; |
3 | int Max = 0; |
4 | int l1 = l(s1), l2 = l(s2); |
5 | for ping (int i = 0; i < l1; i++) { |
6 | for ping (int j = 0; j < l2; j++) { |
7 | int x = 0; |
8 | while (s1.charAt(i + x) == s2.charAt(j + x)) { |
9 | x++; |
10 | if ((i + x) >= l1 || (j + x) >= l2) break; |
11 | } |
12 | if (x > Max) { |
13 | Max = x; |
14 | Start = i; |
15 | } |
16 | } |
17 | } |
18 | ret s1.substring(Start, Start + Max); |
19 | } |
From https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring#Java
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1012478 |
Snippet name: | longestCommonSubstring |
Eternal ID of this version: | #1012478/5 |
Text MD5: | 8cbedafee24d1a6f476441c60fd15088 |
Transpilation MD5: | 66c6814f49a132e7a4b7a4c68ea41e05 |
Author: | stefan |
Category: | javax / strings |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-06 11:28:15 |
Source code size: | 462 bytes / 19 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 420 / 486 |
Version history: | 4 change(s) |
Referenced in: | [show references] |