Merge pull request #1404 from xiaofei-2020/extra04

添加(0283.移动零.md):增加typescript版本
This commit is contained in:
程序员Carl
2022-06-28 11:19:57 +08:00
committed by GitHub

View File

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