mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-08 21:34:17 +08:00
build
This commit is contained in:
@@ -433,7 +433,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
|
||||
fn extend(mem_allocator: std.mem.Allocator, nums: []i32, enlarge: usize) ![]i32 {
|
||||
// 初始化一个扩展长度后的数组
|
||||
var res = try mem_allocator.alloc(i32, nums.len + enlarge);
|
||||
std.mem.set(i32, res, 0);
|
||||
@memset(res, 0);
|
||||
// 将原数组中的所有元素复制到新数组
|
||||
std.mem.copy(i32, res, nums);
|
||||
// 返回扩展后的新数组
|
||||
@@ -1077,7 +1077,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
|
||||
```zig title="array.zig"
|
||||
// 在数组中查找指定元素
|
||||
fn find(nums: []i32, target: i32) i32 {
|
||||
for (nums) |num, i| {
|
||||
for (nums, 0..) |num, i| {
|
||||
if (num == target) return @intCast(i32, i);
|
||||
}
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user