题目链接
https://leetcode.cn/problems/concatenation-of-array/
通过代码一
class Solution {
public int[] getConcatenation(int[] nums) {
int len = nums.length;
int[] ans = new int[len * 2];
for (int i = 0; i < len; i++) {
ans[i] = nums[i];
}
for (int i = len; i < len * 2; i++) {
ans[i] = nums[i- len];
}
return ans;
}
}
通过代码二
class Solution {
public int[] getConcatenation(int[] nums) {
int n = nums.length;
int[] ans = new int[nums.length * 2];
for (int i = 0; i < n; i++) {
ans[i] = ans[n + i] = nums[i];
}
return ans;
}
}
博客给出了LeetCode上数组拼接题目的链接https://leetcode.cn/problems/concatenation-of-array/ ,并展示了该题的两种通过代码,涉及算法和数据结构知识,使用Java语言。
&spm=1001.2101.3001.5002&articleId=128771432&d=1&t=3&u=0af2f2d3977c416c8f93cf6f328cdd68)
344

被折叠的 条评论
为什么被折叠?



