mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-28 04:42:48 +08:00
build
This commit is contained in:
@ -709,8 +709,8 @@ comments: true
|
||||
### 删除索引 index 处的元素 ###
|
||||
def remove(nums, index)
|
||||
# 把索引 index 之后的所有元素向前移动一位
|
||||
for i in index...nums.length
|
||||
nums[i] = nums[i + 1] || 0
|
||||
for i in index...(nums.length - 1)
|
||||
nums[i] = nums[i + 1]
|
||||
end
|
||||
end
|
||||
```
|
||||
@ -949,7 +949,7 @@ comments: true
|
||||
count += nums[i]
|
||||
}
|
||||
// 直接遍历数组元素
|
||||
for (j: Int in nums) {
|
||||
for (j in nums) {
|
||||
count += j
|
||||
}
|
||||
}
|
||||
@ -1155,7 +1155,8 @@ comments: true
|
||||
/* 在数组中查找指定元素 */
|
||||
fun find(nums: IntArray, target: Int): Int {
|
||||
for (i in nums.indices) {
|
||||
if (nums[i] == target) return i
|
||||
if (nums[i] == target)
|
||||
return i
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
Reference in New Issue
Block a user