Skip to content

Commit f028637

Browse files
committed
feat: add solution of Pascals Triangle II(119) with javascript.
1 parent d910064 commit f028637

File tree

11 files changed

+64
-3
lines changed

11 files changed

+64
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
| [111][111-question] | [Minimum Depth of Binary Tree][111-tips] | [Easy][E] | [][111-java] | [][111-js] | [][111-kotlin] |
8383
| [112][112-question] | [Path Sum][112-tips] | [Easy][E] | [][112-java] | [][112-js] | [][112-kotlin] |
8484
| [118][118-question] | [Pascal's Triangle][118-tips] | [Easy][E] | [][118-java] | [][118-js] | [][118-kotlin] |
85-
| [119][119-question] | [Pascal's Triangle II][119-tips] | [Easy][E] | [][119-java] | | [][119-kotlin] |
85+
| [119][119-question] | [Pascal's Triangle II][119-tips] | [Easy][E] | [][119-java] | [][119-js]| [][119-kotlin] |
8686
| [121][121-question] | [Best Time to Buy and Sell Stock][121-tips] | [Easy][E] | [][121-java] | | [][121-kotlin] |
8787
| [122][122-question] | [Best Time to Buy and Sell Stock II][122-tips] | [Easy][E] | [][122-java] | | [][122-kotlin] |
8888
| [125][125-question] | [Valid Palindrome][125-tips] | [Easy][E] | | | [][125-kotlin] |
@@ -462,6 +462,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
462462
[111-js]: ./src/_111/Solution.js
463463
[112-js]: ./src/_112/Solution.js
464464
[118-js]: ./src/_118/Solution.js
465+
[119-js]: ./src/_119/Solution.js
465466
[226-js]: ./src/_226/Solution.js
466467
[561-js]: ./src/_561/Solution.js
467468
[643-js]: ./src/_643/Solution.js

src/_119/Solution.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {number} rowIndex
3+
* @return {number[]}
4+
*/
5+
var getRow = function(rowIndex) {
6+
var rowArr = function(numRows) {
7+
let arr = []
8+
for(var i = 1; i <= numRows; i++) {
9+
if(i === 1) {
10+
arr.push([1])
11+
continue
12+
}
13+
if(i === 2) {
14+
arr.push([1, 1])
15+
continue
16+
}
17+
let innerArr = [1]
18+
for(var j = 2; j < i; j++) {
19+
innerArr.push(arr[i-2][j-2] + arr[i-2][j-1])
20+
}
21+
innerArr.push(1)
22+
arr.push(innerArr)
23+
}
24+
return arr
25+
}
26+
return rowArr(rowIndex + 1)[rowIndex]
27+
};

tips/101/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Solution {
7878
}
7979
```
8080

81-
81+
JavaScript:
8282
```javascript
8383
var isSymmetric = function(root) {
8484
if(root == null) return true

tips/104/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Solution {
4444
}
4545
```
4646

47+
JavaScript:
4748
```javascript
4849
var maxDepth = function(root) {
4950
if (root == null) return 0;

tips/107/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class Solution {
119119
}
120120
```
121121

122+
JavaScript:
122123
```javascript
123124
var levelOrderBottom = function(root) {
124125
if (root === null) { return []; }

tips/108/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Solution {
8585
}
8686
```
8787

88+
JavaScript:
8889
```javascript
8990
var sortedArrayToBST = function(nums) {
9091
if (nums == null || !nums.length) {

tips/110/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Solution {
5959
```
6060

6161

62-
```
62+
JavaScript:
63+
```JavaScript
6364
var isBalanced = function(root) {
6465
if(root == null) return true
6566
var treeDeep = function(root) {

tips/111/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Solution {
4848
}
4949
```
5050

51+
JavaScript:
5152
```JavaScript
5253
var minDepth = function(root) {
5354
if(root == null) return 0

tips/112/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Solution {
5858
}
5959
```
6060

61+
JavaScript:
6162
```JavaScript
6263
var hasPathSum = function(root, sum) {
6364
if(root == null) {

tips/118/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Solution {
6969
}
7070
```
7171

72+
JavaScript:
7273
```JavaScript
7374
var generate = function(numRows) {
7475
let arr = []

tips/119/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ class Solution {
5454
}
5555
```
5656

57+
JavaScript:
58+
```JavaScript
59+
var getRow = function(rowIndex) {
60+
var rowArr = function(numRows) {
61+
let arr = []
62+
for(var i = 1; i <= numRows; i++) {
63+
if(i === 1) {
64+
arr.push([1])
65+
continue
66+
}
67+
if(i === 2) {
68+
arr.push([1, 1])
69+
continue
70+
}
71+
let innerArr = [1]
72+
for(var j = 2; j < i; j++) {
73+
innerArr.push(arr[i-2][j-2] + arr[i-2][j-1])
74+
}
75+
innerArr.push(1)
76+
arr.push(innerArr)
77+
}
78+
return arr
79+
}
80+
return rowArr(rowIndex + 1)[rowIndex]
81+
};
82+
```
5783
## 结语
5884

5985
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[LeetCode-Solution][ls]

0 commit comments

Comments
 (0)