static String commonPrefix(String a, String b) { int i = 0, nb = b.length(), na = a.length(), n = min(na, nb); while (i < n && a.charAt(i) == b.charAt(i)) ++i; return i == nb ? b : substring(a, 0, i); } static S commonPrefix(L<S> l) { if (empty(l)) ret ""; S s = first(l); for (int i = 1; i < l(l); i++) { if (empty(s)) ret s; s = commonPrefix(s, l.get(i)); // Yeah, cold be optimized } ret s; }
Began life as a copy of #2000591
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: | #1013590 |
| Snippet name: | commonPrefix |
| Eternal ID of this version: | #1013590/5 |
| Text MD5: | 75689c3f636d4396bdaa03ceb32caab9 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-04-28 15:14:48 |
| Source code size: | 439 bytes / 16 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 780 / 766 |
| Version history: | 4 change(s) |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1014380 - commonPrefixCI |