Created
October 28, 2016 17:13
-
-
Save toinetoine/1fce8093c343812d8fdf99de31013052 to your computer and use it in GitHub Desktop.
splice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int[] splice(int a[], int offset, int b[]) { | |
int[] resultArray = new int[a.length + b.length]; | |
for(int i = 0; i < resultArray.length; i++) { | |
if (i < offset) { // before the part b should be copied to | |
resultArray[i] = a[i]; | |
} | |
else if (i - offset < b.length) { // in the middle of the part b is copied to | |
resultArray[i] = b[i - offset]; | |
} | |
else { // after the part b was copied to | |
resultArray[i] = a[i - b.length]; | |
} | |
} | |
return resultArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment