为数组篇 增加 Swift 实现

This commit is contained in:
zhenzi
2021-07-17 12:13:15 +08:00
parent 2c4afffbd3
commit c14c2297f1
14 changed files with 702 additions and 1 deletions

View File

@@ -164,3 +164,23 @@ public:
};
```
Swift Code
```swift
class Solution {
func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
if nums.count == 0 {
return 0
}
var i = 0
for j in 0..<nums.count {
if nums[j] != val {
nums[i] = nums[j]
i += 1
}
}
return i
}
}
```