Skip to content

Commit 9bbeafc

Browse files
committed
feat: add typescript solution to lc problem: No.0118.Pascal's Triangle
1 parent 23408da commit 9bbeafc

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

solution/0100-0199/0118.Pascal's Triangle/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ class Solution {
7474
}
7575
```
7676

77+
### **TypeScript**
78+
79+
```ts
80+
function generate(numRows: number): number[][] {
81+
if (numRows == 0) return [];
82+
let ans = [[1]];
83+
for (let i = 1; i < numRows; ++i) {
84+
ans.push(new Array(i + 1).fill(1));
85+
let half = i >> 1;
86+
for (let j = 1;j <= half; ++j) {
87+
let cur = ans[i - 1][j - 1] + ans[i - 1][j];
88+
ans[i][j] = cur;
89+
ans[i][i - j] = cur;
90+
}
91+
}
92+
return ans;
93+
};
94+
```
95+
7796
### **C++**
7897

7998
```cpp

solution/0100-0199/0118.Pascal's Triangle/README_EN.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ class Solution {
6565
}
6666
```
6767

68+
### **TypeScript**
69+
70+
```ts
71+
function generate(numRows: number): number[][] {
72+
if (numRows == 0) return [];
73+
let ans = [[1]];
74+
for (let i = 1; i < numRows; ++i) {
75+
ans.push(new Array(i + 1).fill(1));
76+
let half = i >> 1;
77+
for (let j = 1;j <= half; ++j) {
78+
let cur = ans[i - 1][j - 1] + ans[i - 1][j];
79+
ans[i][j] = cur;
80+
ans[i][i - j] = cur;
81+
}
82+
}
83+
return ans;
84+
};
85+
```
86+
6887
### **C++**
6988

7089
```cpp
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function generate(numRows: number): number[][] {
2+
if (numRows == 0) return [];
3+
let ans = [[1]];
4+
for (let i = 1; i < numRows; ++i) {
5+
ans.push(new Array(i + 1).fill(1));
6+
let half = i >> 1;
7+
for (let j = 1;j <= half; ++j) {
8+
let cur = ans[i - 1][j - 1] + ans[i - 1][j];
9+
ans[i][j] = cur;
10+
ans[i][i - j] = cur;
11+
}
12+
}
13+
return ans;
14+
};

0 commit comments

Comments
 (0)