Libraryless. Click here for Pure Java version (2521L/16K).
1 | // is allowed to return null when result is empty |
2 | static int[] intersectSortedIntArrays(int[] a, int[] b) { |
3 | int i = 0, j = 0, la = l(a), lb = l(b); |
4 | if (la == 0 || lb == 0) null; |
5 | IntBuffer buf = new(max(la, lb)); |
6 | while (i < la && j < lb) { |
7 | int x = a[i], y = b[j]; |
8 | if (x == y) { |
9 | buf.add(x); |
10 | ++i; |
11 | ++j; |
12 | } else if (x < y) |
13 | ++i; |
14 | else |
15 | ++j; |
16 | } |
17 | ret buf.toArray(); |
18 | } |
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: | 185 / 284 |
Version history: | 2 change(s) |
Referenced in: | [show references] |