Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a7bbeb6

Browse files
zhaocchenyanglbme
authored andcommitted
feat: add typescript solution to lc problem: No.0989
No.0989.Add to Array-Form of Integer
1 parent a0f7080 commit a7bbeb6

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

‎solution/0900-0999/0989.Add to Array-Form of Integer/README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ class Solution {
104104
}
105105
```
106106

107+
### **TypeScript**
108+
109+
```ts
110+
function addToArrayForm(num: number[], k: number): number[] {
111+
let arr2 = [...String(k)].map(Number);
112+
let ans = [];
113+
let sum = 0;
114+
while (num.length || arr2.length || sum) {
115+
let a = num.pop() || 0, b = arr2.pop() || 0;
116+
sum += (a + b);
117+
ans.unshift(sum % 10);
118+
sum = Math.floor(sum / 10);
119+
}
120+
return ans;
121+
};
122+
```
123+
107124
### **...**
108125

109126
```

‎solution/0900-0999/0989.Add to Array-Form of Integer/README_EN.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ class Solution {
9797
}
9898
```
9999

100+
### **TypeScript**
101+
102+
```ts
103+
function addToArrayForm(num: number[], k: number): number[] {
104+
let arr2 = [...String(k)].map(Number);
105+
let ans = [];
106+
let sum = 0;
107+
while (num.length || arr2.length || sum) {
108+
let a = num.pop() || 0, b = arr2.pop() || 0;
109+
sum += (a + b);
110+
ans.unshift(sum % 10);
111+
sum = Math.floor(sum / 10);
112+
}
113+
return ans;
114+
};
115+
```
116+
100117
### **...**
101118

102119
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function addToArrayForm(num: number[], k: number): number[] {
2+
let arr2 = [...String(k)].map(Number);
3+
let ans = [];
4+
let sum = 0;
5+
while (num.length || arr2.length || sum) {
6+
let a = num.pop() || 0, b = arr2.pop() || 0;
7+
sum += (a + b);
8+
ans.unshift(sum % 10);
9+
sum = Math.floor(sum / 10);
10+
}
11+
return ans;
12+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /