mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-05 23:21:38 +00:00
为数组篇 增加 Swift 实现
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user