File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
solution/0100-0199/0118.Pascal's Triangle Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,25 @@ class Solution {
74
74
}
75
75
```
76
76
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
+
77
96
### ** C++**
78
97
79
98
``` cpp
Original file line number Diff line number Diff line change @@ -65,6 +65,25 @@ class Solution {
65
65
}
66
66
```
67
67
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
+
68
87
### ** C++**
69
88
70
89
``` cpp
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments