Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1013590 - commonPrefix

JavaX fragment (include)

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));
  }
  ret s;
}

Author comment

Began life as a copy of #2000591

download  show line numbers  debug dex  old transpilations   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1013590
Snippet name: commonPrefix
Eternal ID of this version: #1013590/4
Text MD5: 63b2caa7dbf4e4f43e8f0a34f7bd144e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-20 17:31:19
Source code size: 412 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 327 / 290
Version history: 3 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1013590 & http://1013590.tinybrain.de