mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加(0283.移动零.md):增加typescript版本
This commit is contained in:
@ -133,6 +133,27 @@ var moveZeroes = function(nums) {
|
||||
};
|
||||
```
|
||||
|
||||
TypeScript:
|
||||
|
||||
```typescript
|
||||
function moveZeroes(nums: number[]): void {
|
||||
const length: number = nums.length;
|
||||
let slowIndex: number = 0,
|
||||
fastIndex: number = 0;
|
||||
while (fastIndex < length) {
|
||||
if (nums[fastIndex] !== 0) {
|
||||
nums[slowIndex++] = nums[fastIndex];
|
||||
};
|
||||
fastIndex++;
|
||||
}
|
||||
while (slowIndex < length) {
|
||||
nums[slowIndex++] = 0;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user