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

18
LINES

< > BotCompany Repo | #1029026 // intersectSortedIntArrays

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2521L/16K).

// is allowed to return null when result is empty
static int[] intersectSortedIntArrays(int[] a, int[] b) {
  int i = 0, j = 0, la = l(a), lb = l(b);
  if (la == 0 || lb == 0) null;
  IntBuffer buf = new(max(la, lb));
  while (i < la && j < lb) {
    int x = a[i], y = b[j];
    if (x == y) {
      buf.add(x);
      ++i;
      ++j;
    } else if (x < y)
      ++i;
    else
      ++j;
  }
  ret buf.toArray();
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029026
Snippet name: intersectSortedIntArrays
Eternal ID of this version: #1029026/3
Text MD5: 3bf746e4f6c7ec8a4ec95744f0b35e0b
Transpilation MD5: 4c3854e9cf3d2ad12e56cb8fe6850a1a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-17 01:31:36
Source code size: 429 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 110 / 180
Version history: 2 change(s)
Referenced in: [show references]