This commit is contained in:
krahets
2025-01-14 03:42:21 +08:00
parent ceef41be19
commit 2b5bd017b9
10 changed files with 95 additions and 75 deletions
@@ -924,7 +924,8 @@ comments: true
_count += nums[i];
}
// 直接走訪陣列元素
for num in nums {
_count = 0;
for &num in nums {
_count += num;
}
}
@@ -1359,9 +1360,8 @@ comments: true
// 初始化一個擴展長度後的陣列
let mut res: Vec<i32> = vec![0; nums.len() + enlarge];
// 將原陣列中的所有元素複製到新
for i in 0..nums.len() {
res[i] = nums[i];
}
res[0..nums.len()].copy_from_slice(nums);
// 返回擴展後的新陣列
res
}