Skip to content

Commit 9532601

Browse files
committed
formated with vscode prettier plugin
1 parent bd99401 commit 9532601

35 files changed

+593
-608
lines changed

Diff for: 119__easy__pascals_triangle_ii.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
* @return {number[]}
44
*/
55
var getRow = function(rowIndex) {
6-
let res = new Array(rowIndex+1).fill(0);
7-
res[0] = 1;
8-
/*
6+
let res = new Array(rowIndex + 1).fill(0);
7+
res[0] = 1;
8+
/*
99
1
1010
1,1
1111
1,2,1
1212
1,3,3,1
1313
1,4,6,4,1
1414
*/
15-
for (let i = 0; i < res.length; i++) {
16-
for (let j = i; j > 0; j--) {
17-
if (j === i) res[j] = 1;
18-
else {
19-
res[j] = res[j] + res[j-1];
20-
}
21-
}
15+
for (let i = 0; i < res.length; i++) {
16+
for (let j = i; j > 0; j--) {
17+
if (j === i) res[j] = 1;
18+
else {
19+
res[j] = res[j] + res[j - 1];
20+
}
2221
}
23-
return res;
22+
}
23+
return res;
2424
};

Diff for: 134__medium__binary-tree-inorder-traversal.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
1717
*/
1818

19-
2019
/**
2120
* Recursive
2221
* O(n) time
@@ -25,23 +24,22 @@
2524
* 2m
2625
*/
2726
var inorderTraversal = function(root) {
28-
let res = [];
27+
let res = [];
2928

30-
if (!root) return res;
29+
if (!root) return res;
3130

32-
const inorder = (node) => {
33-
if (!node) return;
31+
const inorder = node => {
32+
if (!node) return;
3433

35-
inorder(node.left);
36-
res.push(node.val);
37-
inorder(node.right);
38-
}
34+
inorder(node.left);
35+
res.push(node.val);
36+
inorder(node.right);
37+
};
3938

40-
inorder(root);
41-
return res;
39+
inorder(root);
40+
return res;
4241
};
4342

44-
4543
/**
4644
* Using Stack
4745
* O(n) time
@@ -50,20 +48,20 @@ var inorderTraversal = function(root) {
5048
* 25m
5149
*/
5250
var inorderTraversal = function(root) {
53-
if (!root) return [];
51+
if (!root) return [];
5452

55-
let res = [];
56-
let st = [];
57-
let curr = root;
53+
let res = [];
54+
let st = [];
55+
let curr = root;
5856

59-
while (curr || st.length > 0) {
60-
while (curr) {
61-
st.push(curr);
62-
curr = curr.left;
63-
}
64-
curr = st.pop();
65-
res.push(curr.val);
66-
curr = curr.right;
57+
while (curr || st.length > 0) {
58+
while (curr) {
59+
st.push(curr);
60+
curr = curr.left;
6761
}
68-
return res;
62+
curr = st.pop();
63+
res.push(curr.val);
64+
curr = curr.right;
65+
}
66+
return res;
6967
};

Diff for: 136__easy__single-number.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* @param {number[]} nums
33
* @return {number}
44
*/
5-
/**
5+
/**
66
*
77
* O(n) time
88
* O(1) space
99
*
1010
* 4m
1111
*/
1212
var singleNumber = function(nums) {
13-
let res = 0;
14-
nums.forEach( n => res ^= n);
15-
return res;
16-
};
13+
let res = 0;
14+
nums.forEach(n => (res ^= n));
15+
return res;
16+
};

Diff for: 144__medium__binary-tree-preorder-traversal.js

+19-21
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@
2626
* 3m
2727
*/
2828
var preorderTraversal = function(root) {
29-
let res = [];
30-
const preorder = (node) => {
31-
if (!node) return;
29+
let res = [];
30+
const preorder = node => {
31+
if (!node) return;
3232

33-
res.push(node.val);
34-
preorder(node.left);
35-
preorder(node.right);
36-
}
37-
preorder(root);
38-
return res;
33+
res.push(node.val);
34+
preorder(node.left);
35+
preorder(node.right);
36+
};
37+
preorder(root);
38+
return res;
3939
};
4040

41-
42-
4341
/**
4442
*
4543
* using Stack
@@ -50,17 +48,17 @@ var preorderTraversal = function(root) {
5048
* 3m
5149
*/
5250
var preorderTraversal = function(root) {
53-
if (!root) return [];
51+
if (!root) return [];
5452

55-
let res = [];
56-
let st = [root];
53+
let res = [];
54+
let st = [root];
5755

58-
while (st.length > 0) {
59-
let node = st.pop();
60-
res.push(node.val);
61-
if (node.right) st.push(node.right);
62-
if (node.left) st.push(node.left);
63-
}
56+
while (st.length > 0) {
57+
let node = st.pop();
58+
res.push(node.val);
59+
if (node.right) st.push(node.right);
60+
if (node.left) st.push(node.left);
61+
}
6462

65-
return res;
63+
return res;
6664
};

Diff for: 145__hard__binary-tree-postorder-traversal.js

+34-36
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
1717
*/
1818

19-
2019
/**
2120
* Recursive
2221
* O(n) time
@@ -25,41 +24,40 @@
2524
* 3m
2625
*/
2726
var postorderTraversal = function(root) {
28-
if (!root) return [];
27+
if (!root) return [];
2928

30-
let res = [];
31-
const postorder = (node) => {
32-
if (!node) return;
29+
let res = [];
30+
const postorder = node => {
31+
if (!node) return;
3332

34-
postorder(node.left);
35-
postorder(node.right);
36-
res.push(node.val);
37-
}
38-
postorder(root);
39-
return res;
33+
postorder(node.left);
34+
postorder(node.right);
35+
res.push(node.val);
36+
};
37+
postorder(root);
38+
return res;
4039
};
4140

42-
4341
/**
4442
* Using Stack
4543
* O(n) time
4644
* O(n) space
4745
*
4846
* 15m
4947
*/
50-
var postorderTraversal = function(root) {
51-
let res = [];
52-
let st = [];
48+
var postorderTraversal = function(root) {
49+
let res = [];
50+
let st = [];
5351

54-
if (!root) return res;
55-
st.push(root);
56-
while (st.length > 0) {
57-
let node = st.pop();
58-
res.unshift(node.val);
59-
if (node.left) st.push(node.left);
60-
if (node.right) st.push(node.right);
61-
}
62-
return res;
52+
if (!root) return res;
53+
st.push(root);
54+
while (st.length > 0) {
55+
let node = st.pop();
56+
res.unshift(node.val);
57+
if (node.left) st.push(node.left);
58+
if (node.right) st.push(node.right);
59+
}
60+
return res;
6361
};
6462

6563
/**
@@ -70,16 +68,16 @@ var postorderTraversal = function(root) {
7068
* 15m
7169
*/
7270
var postorderTraversal = function(root) {
73-
let res = [];
74-
let st = [];
71+
let res = [];
72+
let st = [];
7573

76-
if (!root) return res;
77-
st.push(root);
78-
while (st.length > 0) {
79-
let node = st.pop();
80-
res.push(node.val);
81-
if (node.left) st.push(node.left);
82-
if (node.right) st.push(node.right);
83-
}
84-
return res.reverse();
85-
};
74+
if (!root) return res;
75+
st.push(root);
76+
while (st.length > 0) {
77+
let node = st.pop();
78+
res.push(node.val);
79+
if (node.left) st.push(node.left);
80+
if (node.right) st.push(node.right);
81+
}
82+
return res.reverse();
83+
};

Diff for: 151__medium__reverse_words_in_a_string.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*
1111
*/
1212
var reverseWords = function(str) {
13-
str = str.trim().replace(/\s\s+/g, ' ');
14-
str = str.split(' ');
15-
let lo = 0;
16-
let hi = str.length - 1;
17-
while (lo < hi) {
18-
[str[lo], str[hi]] = [str[hi], str[lo]];
19-
lo++;
20-
hi--;
21-
}
22-
return str.join(' ');
13+
str = str.trim().replace(/\s\s+/g, " ");
14+
str = str.split(" ");
15+
let lo = 0;
16+
let hi = str.length - 1;
17+
while (lo < hi) {
18+
[str[lo], str[hi]] = [str[hi], str[lo]];
19+
lo++;
20+
hi--;
21+
}
22+
return str.join(" ");
2323
};

Diff for: 170__easy__two-sum-iii-data-structure-design.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
*
3636
*/
3737

38-
/**
38+
/**
3939
* Initialize your data structure here.
4040
*/
4141
var TwoSum = function() {
42-
this.hm = new Map();
42+
this.hm = new Map();
4343
};
4444

4545
/**
@@ -48,7 +48,7 @@ var TwoSum = function() {
4848
* @return {void}
4949
*/
5050
TwoSum.prototype.add = function(number) {
51-
this.hm.set(number, (this.hm.get(number) || 0) + 1);
51+
this.hm.set(number, (this.hm.get(number) || 0) + 1);
5252
};
5353

5454
/**
@@ -57,13 +57,13 @@ TwoSum.prototype.add = function(number) {
5757
* @return {boolean}
5858
*/
5959
TwoSum.prototype.find = function(value) {
60-
for (let item of this.hm) {
61-
let target = value - item[0];
62-
if (this.hm.has(target)) {
63-
if (target !== item[0] || this.hm.get(target) > 1) return true;
64-
}
60+
for (let item of this.hm) {
61+
let target = value - item[0];
62+
if (this.hm.has(target)) {
63+
if (target !== item[0] || this.hm.get(target) > 1) return true;
6564
}
66-
return false;
65+
}
66+
return false;
6767
};
6868

6969
/**
@@ -72,5 +72,3 @@ TwoSum.prototype.find = function(value) {
7272
* obj.add(number)
7373
* var param_2 = obj.find(value)
7474
*/
75-
76-

0 commit comments

Comments
 (0)