mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-12 17:40:24 +08:00
build
This commit is contained in:
@@ -122,6 +122,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
|
||||
// 在区间 [0, nums.length) 中随机抽取一个数字
|
||||
int randomIndex = ThreadLocalRandom.current().
|
||||
nextInt(0, nums.length);
|
||||
// 获取并返回随机元素
|
||||
int randomNum = nums[randomIndex];
|
||||
return randomNum;
|
||||
}
|
||||
@@ -417,7 +418,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex
|
||||
// 将 num 赋给 index 处元素
|
||||
nums[index] = num;
|
||||
}
|
||||
|
||||
|
||||
/* 删除索引 index 处元素 */
|
||||
void remove(int[] nums, int index) {
|
||||
// 把索引 index 之后的所有元素向前移动一位
|
||||
|
||||
@@ -331,7 +331,7 @@ comments: true
|
||||
n0.next = P;
|
||||
P.next = n1;
|
||||
}
|
||||
|
||||
|
||||
/* 删除链表的结点 n0 之后的首个结点 */
|
||||
void remove(ListNode n0) {
|
||||
if (n0.next == null)
|
||||
|
||||
@@ -801,6 +801,17 @@ comments: true
|
||||
// 更新列表容量
|
||||
capacity = nums.length;
|
||||
}
|
||||
|
||||
/* 将列表转换为数组 */
|
||||
public int[] toArray() {
|
||||
int size = size();
|
||||
// 仅转换有效长度范围内的列表元素
|
||||
int[] nums = new int[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
nums[i] = get(i);
|
||||
}
|
||||
return nums;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user