This commit is contained in:
krahets
2024-04-07 03:05:15 +08:00
parent aea68142f8
commit d8caf02e9e
21 changed files with 118 additions and 101 deletions

View File

@ -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
}