Skip to content

Commit

Permalink
feat: add typescript solution to lc problem: No.2149
Browse files Browse the repository at this point in the history
No.2149.Rearrange Array Elements by Sign
  • Loading branch information
zhaocchen committed Jan 28, 2022
1 parent 76747eb commit 5a5333d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,20 @@ func rearrangeArray(nums []int) []int {
<!-- 这里可写当前语言的特殊实现逻辑 -->

```ts

function rearrangeArray(nums: number[]): number[] {
let ans = [];
let i = 0, j = 1;
for (let num of nums) {
if (num > 0) {
ans[i] = num;
i += 2;
} else {
ans[j] = num;
j += 2;
}
}
return ans;
};
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,20 @@ func rearrangeArray(nums []int) []int {
### **TypeScript**

```ts

function rearrangeArray(nums: number[]): number[] {
let ans = [];
let i = 0, j = 1;
for (let num of nums) {
if (num > 0) {
ans[i] = num;
i += 2;
} else {
ans[j] = num;
j += 2;
}
}
return ans;
};
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function rearrangeArray(nums: number[]): number[] {
let ans = [];
let i = 0, j = 1;
for (let num of nums) {
if (num > 0) {
ans[i] = num;
i += 2;
} else {
ans[j] = num;
j += 2;
}
}
return ans;
};

0 comments on commit 5a5333d

Please sign in to comment.