mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 22:46:07 +00:00
build
This commit is contained in:
@@ -299,7 +299,7 @@ Accessing elements in an array is highly efficient, allowing us to randomly acce
|
||||
### 随机访问元素 ###
|
||||
def random_access(nums)
|
||||
# 在区间 [0, nums.length) 中随机抽取一个数字
|
||||
random_index = Random.rand 0...(nums.length - 1)
|
||||
random_index = Random.rand(0...nums.length)
|
||||
|
||||
# 获取并返回随机元素
|
||||
nums[random_index]
|
||||
|
||||
@@ -2154,7 +2154,7 @@ To enhance our understanding of how lists work, we will attempt to implement a s
|
||||
@capacity = 10
|
||||
@size = 0
|
||||
@extend_ratio = 2
|
||||
@arr = Array.new capacity
|
||||
@arr = Array.new(capacity)
|
||||
end
|
||||
|
||||
### 访问元素 ###
|
||||
@@ -2226,9 +2226,9 @@ To enhance our understanding of how lists work, we will attempt to implement a s
|
||||
def to_array
|
||||
sz = size
|
||||
# 仅转换有效长度范围内的列表元素
|
||||
arr = Array.new sz
|
||||
arr = Array.new(sz)
|
||||
for i in 0...sz
|
||||
arr[i] = get i
|
||||
arr[i] = get(i)
|
||||
end
|
||||
arr
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user