Skip to content

Commit ae57b64

Browse files
authored
Create 1929-concatenation-of-array.kt
1 parent 94bbd8b commit ae57b64

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

kotlin/1929-concatenation-of-array.kt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Can be generalized to repeat(x) easier
3+
*/
4+
class Solution {
5+
fun getConcatenation(nums: IntArray): IntArray {
6+
val ans = LinkedList<Int>()
7+
repeat(2) {
8+
for(num in nums)
9+
ans.addLast(num)
10+
}
11+
return ans.toIntArray()
12+
}
13+
}
14+
15+
/*
16+
* concrete solution
17+
*/
18+
class Solution {
19+
fun getConcatenation(nums: IntArray): IntArray {
20+
val ans = IntArray(nums.size * 2)
21+
for(i in 0..nums.lastIndex) {
22+
ans[i] = nums[i]
23+
ans[i + nums.size] = nums[i]
24+
}
25+
return ans
26+
}
27+
}

0 commit comments

Comments
 (0)