mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Update a comment in randomAccess()
This commit is contained in:
@@ -11,8 +11,10 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
/* 随机返回一个数组元素 */
|
||||
public static int RandomAccess(int[] nums)
|
||||
{
|
||||
Random random = new();
|
||||
Random random=new();
|
||||
// 在区间 [0, nums.Length) 中随机抽取一个数字
|
||||
int randomIndex = random.Next(nums.Length);
|
||||
// 获取并返回随机元素
|
||||
int randomNum = nums[randomIndex];
|
||||
return randomNum;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ from include import *
|
||||
|
||||
""" 随机访问元素 """
|
||||
def randomAccess(nums):
|
||||
# 在区间 [0, len(nums)) 中随机抽取一个数字
|
||||
random_index = random.randint(0, len(nums))
|
||||
# 在区间 [0, len(nums)-1] 中随机抽取一个数字
|
||||
random_index = random.randint(0, len(nums) - 1)
|
||||
# 获取并返回随机元素
|
||||
random_num = nums[random_index]
|
||||
return random_num
|
||||
|
||||
Reference in New Issue
Block a user