You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
intn = nums.length; //Creates a variable named n that is the length of nums
14
+
int[] ans = newint[2 * n]; //Creates a new array that is double the size of n.
15
+
16
+
17
+
for (inti = 0; i < n; ++i) {
18
+
ans[i] = nums[i]; //Gets the first half of the int array
19
+
ans[i + n] = nums[i]; //Gets the second half of the int array
20
+
}
21
+
returnans;
22
+
}
23
+
24
+
25
+
publicstaticvoidmain(String[] args) {
26
+
27
+
//Creates an instance of the solution class
28
+
//We need this because getConcatenation() is a method that is non-static meaning we need and object of Solution to use it.
29
+
//This would be unneeded if getConcatenation() was static
30
+
31
+
32
+
int[] nums = {1, 2, 3, 4}; //Array of nums based on Test input
33
+
int[] result = getConcatenation(nums); //calls the getConcatenation method giving it the array of nums.
34
+
35
+
36
+
//Prints result out.
37
+
38
+
//You need to loop out the result because we want to display the contents of an array which means we need to call each instance in it. This is easily done by using the for else loop to run until it is returned false.
0 commit comments