mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加(0027.移除元素.md):增加 typescript 版本
This commit is contained in:
@ -197,7 +197,23 @@ var removeElement = (nums, val) => {
|
||||
};
|
||||
```
|
||||
|
||||
TypeScript:
|
||||
|
||||
```typescript
|
||||
function removeElement(nums: number[], val: number): number {
|
||||
let slowIndex: number = 0, fastIndex: number = 0;
|
||||
while (fastIndex < nums.length) {
|
||||
if (nums[fastIndex] !== val) {
|
||||
nums[slowIndex++] = nums[fastIndex];
|
||||
}
|
||||
fastIndex++;
|
||||
}
|
||||
return slowIndex;
|
||||
};
|
||||
```
|
||||
|
||||
Ruby:
|
||||
|
||||
```ruby
|
||||
def remove_element(nums, val)
|
||||
i = 0
|
||||
|
Reference in New Issue
Block a user